Bug 30520 - Enable creation of custom SidebarTreeElements for different ProfileTypes
Summary: Enable creation of custom SidebarTreeElements for different ProfileTypes
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (Deprecated) (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-19 10:16 PDT by Alexander Pavlov (apavlov)
Modified: 2009-10-21 06:57 PDT (History)
3 users (show)

See Also:


Attachments
patch (5.10 KB, patch)
2009-10-19 11:17 PDT, Alexander Pavlov (apavlov)
timothy: review-
Details | Formatted Diff | Diff
patch (fixed) (4.41 KB, patch)
2009-10-20 03:20 PDT, Alexander Pavlov (apavlov)
pfeldman: review-
Details | Formatted Diff | Diff
patch (rename field) (4.45 KB, patch)
2009-10-21 03:30 PDT, Alexander Pavlov (apavlov)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Pavlov (apavlov) 2009-10-19 10:16:05 PDT
Currently ProfileSidebarTreeElement is always created as the sidebar tree node for profiles. This is too limiting for some types of profiles which would rather provide their own tree elements (e.g. they require non-empty subtitles).
Comment 1 Alexander Pavlov (apavlov) 2009-10-19 11:17:41 PDT
Created attachment 41433 [details]
patch
Comment 2 Timothy Hatcher 2009-10-19 11:40:48 PDT
Comment on attachment 41433 [details]
patch

> +    sidebarTreeElementForProfile: function(profile)
> +    {
> +        return new WebInspector.ProfileSidebarTreeElement(profile);
> +    },

Why does this return a new tree element each time? Shouldn't this return the same one each time? If not, then this function needs a "create" prefix.


> +    createView: function(profile)
> +    {
> +        return undefined;
> +    },
> +
> +    sidebarTreeElementForProfile: function(profile)
> +    {
> +        return undefined;
> +    },

It is better to use null in cases like this. But why do these exist?


> +    viewForProfile: function(profile)
> +    {
> +        if (!profile._profileView)
> +            profile._profileView = this.createView(profile);
> +        return profile._profileView;
>      }

I am confused why there are multiple versions of these functions. Also this clearly calls "this.createView", which just returns undefined. Can you explain this? I don't think the functions that just return "undefined" are needed or useful.


> +    _parseKey: function(key)
> +    {
> +        var match = key.match(/^([^\/]+)\/([^\/]+)$/);
> +        if (match)
> +            return [unescape(match[1]), unescape(match[2])];
> +        return undefined;
> +    },

Better to return null.


> +    _viewForProfile: function(profile)
> +    {
> +        for (var key in this._profilesIdMap) {
> +            if (this._profilesIdMap[key] === profile) {
> +                var parsedKey = this._parseKey(key);
> +                if (parsedKey)
> +                    return this.getProfileType(parsedKey[1]).viewForProfile(profile);
> +            }
> +        }
> +        return undefined;
> +    },

Better to return null.


r-. This needs clerified and not have functions that do nothing but return undefined. (Or explained with good comments.)
Comment 3 Pavel Feldman 2009-10-19 11:49:30 PDT
> +    _viewForProfile: function(profile)
> +    {
> +        for (var key in this._profilesIdMap) {
> +            if (this._profilesIdMap[key] === profile) {
> +                var parsedKey = this._parseKey(key);
> +                if (parsedKey)
> +                    return this.getProfileType(parsedKey[1]).viewForProfile(profile);

This sounds much more complex than "profile.type.viewForProfile(profile)".
Should we make profile have this property in order to get rid of key parsing?
Comment 4 Alexander Pavlov (apavlov) 2009-10-19 13:10:55 PDT
(In reply to comment #3)
> > +    _viewForProfile: function(profile)
> > +    {
> > +        for (var key in this._profilesIdMap) {
> > +            if (this._profilesIdMap[key] === profile) {
> > +                var parsedKey = this._parseKey(key);
> > +                if (parsedKey)
> > +                    return this.getProfileType(parsedKey[1]).viewForProfile(profile);
> 
> This sounds much more complex than "profile.type.viewForProfile(profile)".
> Should we make profile have this property in order to get rid of key parsing?

Good point. I was trying to decrease coupling as much as possible but this one seems fine.
Comment 5 Timothy Hatcher 2009-10-19 13:22:10 PDT
Comment on attachment 41433 [details]
patch

I understand this design better now. You should add comments to each function that the ProfileType subclasses should implement.

I also think ProfileType.sidebarTreeElementForProfile should be ProfileType.createSidebarTreeElementForProfile to show it returns a new instance each time.
Comment 6 Alexander Pavlov (apavlov) 2009-10-20 03:20:56 PDT
Created attachment 41493 [details]
patch (fixed)
Comment 7 Pavel Feldman 2009-10-20 15:47:13 PDT
Comment on attachment 41493 [details]
patch (fixed)

> +    // Must be implemented by subclasses.
> +    createView: function(profile)

Nit, can be done in subsequent patch: usually abstract methods that are implemented in concrete classes are named as doCreateSomething*.
Otherwise it is easy to get confused on what should be overriden and what not.

> +    {
> +        throw new Error("Needs implemented.");
> +    },

"Not implemented" ?

>  
> +        profile._type = profileType;

This looks like a hack: what if concrete profile object already has this property?
Either declare it a hack and name it "__profilesPanelProfileType" or make profile define "type" getter and put it into docs.
Comment 8 Timothy Hatcher 2009-10-20 17:04:25 PDT
(In reply to comment #7)
> (From update of attachment 41493 [details])
> > +    // Must be implemented by subclasses.
> > +    createView: function(profile)
> 
> Nit, can be done in subsequent patch: usually abstract methods that are
> implemented in concrete classes are named as doCreateSomething*.
> Otherwise it is easy to get confused on what should be overriden and what not.

This is not something we normally do in WebKit. I think the normal names are better.
Comment 9 Alexander Pavlov (apavlov) 2009-10-21 03:25:59 PDT
(In reply to comment #7)
> (From update of attachment 41493 [details])
> > +    // Must be implemented by subclasses.
> > +    createView: function(profile)
> 
> Nit, can be done in subsequent patch: usually abstract methods that are
> implemented in concrete classes are named as doCreateSomething*.
> Otherwise it is easy to get confused on what should be overriden and what not.

Timothy has commented on this one.

> > +    {
> > +        throw new Error("Needs implemented.");
> > +    },
> 
> "Not implemented" ?

This is fine, as in "Has a comment that points out this needs implemented when network headers are added" (WebCore/ChangeLog, 2008-05-13) or at the bottom of Comment #2. And, it was suggested by Timothy.

> >  
> > +        profile._type = profileType;
> 
> This looks like a hack: what if concrete profile object already has this
> property?
> Either declare it a hack and name it "__profilesPanelProfileType" or make
> profile define "type" getter and put it into docs.

Profiles should be definitely ProfileType-agnostic since ProfileTypes deal with visual representation of profiles, and they are bound only at the point of the addProfileHeader() invocation. That's why I was parsing the keys (which was cleaner than "caching" ProfileTypes inside profiles) rather than using an explicit association. I will stick to "__profilesPanelProfileType".
Comment 10 Alexander Pavlov (apavlov) 2009-10-21 03:30:55 PDT
Created attachment 41560 [details]
patch (rename field)

Renamed the "cached" ProfileType field inside profiles.
Comment 11 WebKit Commit Bot 2009-10-21 06:57:20 PDT
Comment on attachment 41560 [details]
patch (rename field)

Clearing flags on attachment: 41560

Committed r49905: <http://trac.webkit.org/changeset/49905>
Comment 12 WebKit Commit Bot 2009-10-21 06:57:25 PDT
All reviewed patches have been landed.  Closing bug.