Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: chrome/browser/ui/intents/web_intents_model.h

Issue 11087022: intents: Change default_service_url() to return a const-ref. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rm virtual dtor Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_UI_INTENTS_WEB_INTENTS_MODEL_H_ 5 #ifndef CHROME_BROWSER_UI_INTENTS_WEB_INTENTS_MODEL_H_
6 #define CHROME_BROWSER_UI_INTENTS_WEB_INTENTS_MODEL_H_ 6 #define CHROME_BROWSER_UI_INTENTS_WEB_INTENTS_MODEL_H_
7 7
8 #include "base/basictypes.h"
8 #include "base/values.h" 9 #include "base/values.h"
9 #include "chrome/browser/intents/web_intents_registry.h"
10 #include "ui/base/models/tree_node_model.h" 10 #include "ui/base/models/tree_node_model.h"
11 #include "webkit/glue/web_intent_service_data.h"
11 12
12 class WebIntentsRegistry; 13 class WebIntentsRegistry;
13 struct DefaultWebIntentService;
14 14
15 // The tree structure is a TYPE_ROOT node with title="", 15 // The tree structure is a TYPE_ROOT node with title="",
16 // children are TYPE_ORIGIN nodes with title=origin, whose 16 // children are TYPE_ORIGIN nodes with title=origin, whose
17 // children are TYPE_SERVICE nodes with title=origin, and 17 // children are TYPE_SERVICE nodes with title=origin, and
18 // will be of type ServiceTreeNode with data on individual 18 // will be of type ServiceTreeNode with data on individual
19 // services. 19 // services.
20 class WebIntentsTreeNode : public ui::TreeNode<WebIntentsTreeNode> { 20 class WebIntentsTreeNode : public ui::TreeNode<WebIntentsTreeNode> {
21 public: 21 public:
22 WebIntentsTreeNode();
23 explicit WebIntentsTreeNode(const string16& title);
24
25 virtual ~WebIntentsTreeNode();
26
27 enum NodeType { 22 enum NodeType {
28 TYPE_ROOT, 23 TYPE_ROOT,
29 TYPE_ORIGIN, 24 TYPE_ORIGIN,
30 TYPE_SERVICE, 25 TYPE_SERVICE,
31 }; 26 };
32 27
28 WebIntentsTreeNode();
29 explicit WebIntentsTreeNode(const string16& title);
30 virtual ~WebIntentsTreeNode();
31
33 NodeType Type() const { return type_; } 32 NodeType Type() const { return type_; }
34 33
35 protected: 34 protected:
36 WebIntentsTreeNode(const string16& title, NodeType type) 35 WebIntentsTreeNode(const string16& title, NodeType type)
37 : ui::TreeNode<WebIntentsTreeNode>(title), 36 : ui::TreeNode<WebIntentsTreeNode>(title),
38 type_(type) {} 37 type_(type) {}
39 38
40 private: 39 private:
41 NodeType type_; 40 NodeType type_;
41
42 DISALLOW_COPY_AND_ASSIGN(WebIntentsTreeNode);
42 }; 43 };
43 44
44 // Tree node representing particular services presented by an origin. 45 // Tree node representing particular services presented by an origin.
45 class ServiceTreeNode : public WebIntentsTreeNode { 46 class ServiceTreeNode : public WebIntentsTreeNode {
46 public: 47 public:
47 explicit ServiceTreeNode(const string16& title); 48 explicit ServiceTreeNode(const string16& title);
48 virtual ~ServiceTreeNode(); 49 virtual ~ServiceTreeNode();
49 50
50 const string16& ServiceName() const { return service_name_; } 51 const string16& ServiceName() const { return service_name_; }
51 const string16& ServiceUrl() const { return service_url_; } 52 const string16& ServiceUrl() const { return service_url_; }
52 const string16& IconUrl() const { return icon_url_; } 53 const string16& IconUrl() const { return icon_url_; }
53 const string16& Action() const { return action_; } 54 const string16& Action() const { return action_; }
54 const base::ListValue& Types() const { return types_; } 55 const base::ListValue& Types() const { return types_; }
55 bool IsBlocked() const { return blocked_; } 56 bool IsBlocked() const { return blocked_; }
56 bool IsDisabled() const { return disabled_; } 57 bool IsDisabled() const { return disabled_; }
57 58
58 void SetServiceName(string16 name) { service_name_ = name; } 59 void SetServiceName(const string16& name) { service_name_ = name; }
59 void SetServiceUrl(string16 url) { service_url_ = url; } 60 void SetServiceUrl(const string16& url) { service_url_ = url; }
60 void SetIconUrl(string16 url) { icon_url_ = url; } 61 void SetIconUrl(const string16& url) { icon_url_ = url; }
61 void SetAction(string16 action) { action_ = action; } 62 void SetAction(const string16& action) { action_ = action; }
62 void AddType(string16 type) { types_.Append(Value::CreateStringValue(type)); } 63 void AddType(const string16& type) {
64 types_.Append(base::Value::CreateStringValue(type));
65 }
63 void SetBlocked(bool blocked) { blocked_ = blocked; } 66 void SetBlocked(bool blocked) { blocked_ = blocked; }
64 void SetDisabled(bool disabled) { disabled_ = disabled; } 67 void SetDisabled(bool disabled) { disabled_ = disabled; }
65 68
66 private: 69 private:
67 string16 service_name_; 70 string16 service_name_;
68 string16 icon_url_; 71 string16 icon_url_;
69 string16 service_url_; 72 string16 service_url_;
70 string16 action_; 73 string16 action_;
71 base::ListValue types_; 74 base::ListValue types_;
72 75
73 // TODO(gbillock): these are kind of a placeholder for exceptions data. 76 // TODO(gbillock): these are kind of a placeholder for exceptions data.
74 bool blocked_; 77 bool blocked_;
75 bool disabled_; 78 bool disabled_;
79
80 DISALLOW_COPY_AND_ASSIGN(ServiceTreeNode);
76 }; 81 };
77 82
78 // UI-backing tree model of the data in the WebIntentsRegistry. 83 // UI-backing tree model of the data in the WebIntentsRegistry.
79 class WebIntentsModel : public ui::TreeNodeModel<WebIntentsTreeNode> { 84 class WebIntentsModel : public ui::TreeNodeModel<WebIntentsTreeNode> {
80 public: 85 public:
81 // Because nodes are fetched in a background thread, they are not 86 // Because nodes are fetched in a background thread, they are not
82 // present at the time the Model is created. The Model then notifies its 87 // present at the time the Model is created. The Model then notifies its
83 // observers for every item added. 88 // observers for every item added.
84 class Observer : public ui::TreeModelObserver { 89 class Observer : public ui::TreeModelObserver {
85 public: 90 public:
86 virtual void TreeModelBeginBatch(WebIntentsModel* model) {} 91 virtual void TreeModelBeginBatch(WebIntentsModel* model) {}
87 virtual void TreeModelEndBatch(WebIntentsModel* model) {} 92 virtual void TreeModelEndBatch(WebIntentsModel* model) {}
88 }; 93 };
89 94
90 explicit WebIntentsModel(WebIntentsRegistry* intents_registry); 95 explicit WebIntentsModel(WebIntentsRegistry* intents_registry);
91 virtual ~WebIntentsModel(); 96 virtual ~WebIntentsModel();
92 97
93 void AddWebIntentsTreeObserver(Observer* observer); 98 void AddWebIntentsTreeObserver(Observer* observer);
94 void RemoveWebIntentsTreeObserver(Observer* observer); 99 void RemoveWebIntentsTreeObserver(Observer* observer);
95 100
96 string16 GetTreeNodeId(WebIntentsTreeNode* node); 101 string16 GetTreeNodeId(WebIntentsTreeNode* node);
97 WebIntentsTreeNode* GetTreeNode(std::string path_id); 102 WebIntentsTreeNode* GetTreeNode(const std::string& path_id);
98 void GetChildNodeList(WebIntentsTreeNode* parent, int start, int count, 103 void GetChildNodeList(WebIntentsTreeNode* parent,
104 int start,
105 int count,
99 base::ListValue* nodes); 106 base::ListValue* nodes);
100 void GetWebIntentsTreeNodeDictionary(const WebIntentsTreeNode& node, 107 void GetWebIntentsTreeNodeDictionary(const WebIntentsTreeNode& node,
101 base::DictionaryValue* dict); 108 base::DictionaryValue* dict);
102 109
103 void OnIntentsQueryDone( 110 void OnIntentsQueryDone(
104 const std::vector<webkit_glue::WebIntentServiceData>& services); 111 const std::vector<webkit_glue::WebIntentServiceData>& services);
105 112
106 private: 113 private:
107 // Loads the data model from the WebIntentsRegistry. 114 // Loads the data model from the WebIntentsRegistry.
108 // TODO(gbillock): need an observer on that to absorb async updates? 115 // TODO(gbillock): need an observer on that to absorb async updates?
109 void LoadModel(); 116 void LoadModel();
110 117
111 // Get the model node for a particular host. 118 // Get the model node for a particular host.
112 WebIntentsTreeNode* GetNodeForHost(const std::string& host); 119 WebIntentsTreeNode* GetNodeForHost(const std::string& host);
113 120
114 // Do batch-specific notifies for updates coming from the LoadModel. 121 // Do batch-specific notifies for updates coming from the LoadModel.
115 void NotifyObserverBeginBatch(); 122 void NotifyObserverBeginBatch();
116 void NotifyObserverEndBatch(); 123 void NotifyObserverEndBatch();
117 124
118 // The backing registry. Weak pointer. 125 // The backing registry. Weak pointer.
119 WebIntentsRegistry* intents_registry_; 126 WebIntentsRegistry* intents_registry_;
120 127
121 // Separate list of observers that'll get batch updates. 128 // Separate list of observers that'll get batch updates.
122 ObserverList<Observer> intents_observer_list_; 129 ObserverList<Observer> intents_observer_list_;
123 130
124 // Batch update nesting level. Incremented to indicate that we're in 131 // Batch update nesting level. Incremented to indicate that we're in
125 // the middle of a batch update. 132 // the middle of a batch update.
126 int batch_update_; 133 int batch_update_;
134
135 DISALLOW_COPY_AND_ASSIGN(WebIntentsModel);
127 }; 136 };
128 137
129 #endif // CHROME_BROWSER_UI_INTENTS_WEB_INTENTS_MODEL_H_ 138 #endif // CHROME_BROWSER_UI_INTENTS_WEB_INTENTS_MODEL_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/intents/web_intent_picker_model.h ('k') | chrome/browser/ui/intents/web_intents_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698