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

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: 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
« no previous file with comments | « chrome/browser/ui/intents/web_intent_picker_model.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/intents/web_intents_registry.h"
10 #include "ui/base/models/tree_node_model.h" 11 #include "ui/base/models/tree_node_model.h"
11 12
12 class WebIntentsRegistry; 13 class WebIntentsRegistry;
13 struct DefaultWebIntentService; 14 struct DefaultWebIntentService;
14 15
15 // The tree structure is a TYPE_ROOT node with title="", 16 // The tree structure is a TYPE_ROOT node with title="",
16 // children are TYPE_ORIGIN nodes with title=origin, whose 17 // children are TYPE_ORIGIN nodes with title=origin, whose
17 // children are TYPE_SERVICE nodes with title=origin, and 18 // children are TYPE_SERVICE nodes with title=origin, and
18 // will be of type ServiceTreeNode with data on individual 19 // will be of type ServiceTreeNode with data on individual
19 // services. 20 // services.
20 class WebIntentsTreeNode : public ui::TreeNode<WebIntentsTreeNode> { 21 class WebIntentsTreeNode : public ui::TreeNode<WebIntentsTreeNode> {
21 public: 22 public:
22 WebIntentsTreeNode();
23 explicit WebIntentsTreeNode(const string16& title);
24
25 virtual ~WebIntentsTreeNode();
26
27 enum NodeType { 23 enum NodeType {
28 TYPE_ROOT, 24 TYPE_ROOT,
29 TYPE_ORIGIN, 25 TYPE_ORIGIN,
30 TYPE_SERVICE, 26 TYPE_SERVICE,
31 }; 27 };
32 28
29 WebIntentsTreeNode();
30 explicit WebIntentsTreeNode(const string16& title);
31 virtual ~WebIntentsTreeNode();
32
33 NodeType Type() const { return type_; } 33 NodeType Type() const { return type_; }
34 34
35 protected: 35 protected:
36 WebIntentsTreeNode(const string16& title, NodeType type) 36 WebIntentsTreeNode(const string16& title, NodeType type)
37 : ui::TreeNode<WebIntentsTreeNode>(title), 37 : ui::TreeNode<WebIntentsTreeNode>(title),
38 type_(type) {} 38 type_(type) {}
39 39
40 private: 40 private:
41 NodeType type_; 41 NodeType type_;
42
43 DISALLOW_COPY_AND_ASSIGN(WebIntentsTreeNode);
42 }; 44 };
43 45
44 // Tree node representing particular services presented by an origin. 46 // Tree node representing particular services presented by an origin.
45 class ServiceTreeNode : public WebIntentsTreeNode { 47 class ServiceTreeNode : public WebIntentsTreeNode {
46 public: 48 public:
47 explicit ServiceTreeNode(const string16& title); 49 explicit ServiceTreeNode(const string16& title);
48 virtual ~ServiceTreeNode(); 50 virtual ~ServiceTreeNode();
49 51
50 const string16& ServiceName() const { return service_name_; } 52 const string16& ServiceName() const { return service_name_; }
tfarina 2012/10/09 01:43:54 this probably should follow the unix_hacker() styl
51 const string16& ServiceUrl() const { return service_url_; } 53 const string16& ServiceUrl() const { return service_url_; }
52 const string16& IconUrl() const { return icon_url_; } 54 const string16& IconUrl() const { return icon_url_; }
53 const string16& Action() const { return action_; } 55 const string16& Action() const { return action_; }
54 const base::ListValue& Types() const { return types_; } 56 const base::ListValue& Types() const { return types_; }
55 bool IsBlocked() const { return blocked_; } 57 bool IsBlocked() const { return blocked_; }
56 bool IsDisabled() const { return disabled_; } 58 bool IsDisabled() const { return disabled_; }
57 59
58 void SetServiceName(string16 name) { service_name_ = name; } 60 void SetServiceName(const string16& name) { service_name_ = name; }
59 void SetServiceUrl(string16 url) { service_url_ = url; } 61 void SetServiceUrl(const string16& url) { service_url_ = url; }
60 void SetIconUrl(string16 url) { icon_url_ = url; } 62 void SetIconUrl(const string16& url) { icon_url_ = url; }
61 void SetAction(string16 action) { action_ = action; } 63 void SetAction(const string16& action) { action_ = action; }
62 void AddType(string16 type) { types_.Append(Value::CreateStringValue(type)); } 64 void AddType(const string16& type) {
65 types_.Append(Value::CreateStringValue(type));
66 }
63 void SetBlocked(bool blocked) { blocked_ = blocked; } 67 void SetBlocked(bool blocked) { blocked_ = blocked; }
64 void SetDisabled(bool disabled) { disabled_ = disabled; } 68 void SetDisabled(bool disabled) { disabled_ = disabled; }
65 69
66 private: 70 private:
67 string16 service_name_; 71 string16 service_name_;
68 string16 icon_url_; 72 string16 icon_url_;
69 string16 service_url_; 73 string16 service_url_;
70 string16 action_; 74 string16 action_;
71 base::ListValue types_; 75 base::ListValue types_;
72 76
73 // TODO(gbillock): these are kind of a placeholder for exceptions data. 77 // TODO(gbillock): these are kind of a placeholder for exceptions data.
74 bool blocked_; 78 bool blocked_;
75 bool disabled_; 79 bool disabled_;
80
81 DISALLOW_COPY_AND_ASSIGN(ServiceTreeNode);
76 }; 82 };
77 83
78 // UI-backing tree model of the data in the WebIntentsRegistry. 84 // UI-backing tree model of the data in the WebIntentsRegistry.
79 class WebIntentsModel : public ui::TreeNodeModel<WebIntentsTreeNode> { 85 class WebIntentsModel : public ui::TreeNodeModel<WebIntentsTreeNode> {
80 public: 86 public:
81 // Because nodes are fetched in a background thread, they are not 87 // 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 88 // present at the time the Model is created. The Model then notifies its
83 // observers for every item added. 89 // observers for every item added.
84 class Observer : public ui::TreeModelObserver { 90 class Observer : public ui::TreeModelObserver {
85 public: 91 public:
92 virtual ~Observer() {}
93
86 virtual void TreeModelBeginBatch(WebIntentsModel* model) {} 94 virtual void TreeModelBeginBatch(WebIntentsModel* model) {}
87 virtual void TreeModelEndBatch(WebIntentsModel* model) {} 95 virtual void TreeModelEndBatch(WebIntentsModel* model) {}
88 }; 96 };
89 97
90 explicit WebIntentsModel(WebIntentsRegistry* intents_registry); 98 explicit WebIntentsModel(WebIntentsRegistry* intents_registry);
91 virtual ~WebIntentsModel(); 99 virtual ~WebIntentsModel();
92 100
93 void AddWebIntentsTreeObserver(Observer* observer); 101 void AddWebIntentsTreeObserver(Observer* observer);
94 void RemoveWebIntentsTreeObserver(Observer* observer); 102 void RemoveWebIntentsTreeObserver(Observer* observer);
95 103
96 string16 GetTreeNodeId(WebIntentsTreeNode* node); 104 string16 GetTreeNodeId(WebIntentsTreeNode* node);
97 WebIntentsTreeNode* GetTreeNode(std::string path_id); 105 WebIntentsTreeNode* GetTreeNode(const std::string& path_id);
98 void GetChildNodeList(WebIntentsTreeNode* parent, int start, int count, 106 void GetChildNodeList(WebIntentsTreeNode* parent,
107 int start,
108 int count,
99 base::ListValue* nodes); 109 base::ListValue* nodes);
100 void GetWebIntentsTreeNodeDictionary(const WebIntentsTreeNode& node, 110 void GetWebIntentsTreeNodeDictionary(const WebIntentsTreeNode& node,
101 base::DictionaryValue* dict); 111 base::DictionaryValue* dict);
102 112
103 void OnIntentsQueryDone( 113 void OnIntentsQueryDone(
104 const std::vector<webkit_glue::WebIntentServiceData>& services); 114 const std::vector<webkit_glue::WebIntentServiceData>& services);
105 115
106 private: 116 private:
107 // Loads the data model from the WebIntentsRegistry. 117 // Loads the data model from the WebIntentsRegistry.
108 // TODO(gbillock): need an observer on that to absorb async updates? 118 // TODO(gbillock): need an observer on that to absorb async updates?
109 void LoadModel(); 119 void LoadModel();
110 120
111 // Get the model node for a particular host. 121 // Get the model node for a particular host.
112 WebIntentsTreeNode* GetNodeForHost(const std::string& host); 122 WebIntentsTreeNode* GetNodeForHost(const std::string& host);
113 123
114 // Do batch-specific notifies for updates coming from the LoadModel. 124 // Do batch-specific notifies for updates coming from the LoadModel.
115 void NotifyObserverBeginBatch(); 125 void NotifyObserverBeginBatch();
116 void NotifyObserverEndBatch(); 126 void NotifyObserverEndBatch();
117 127
118 // The backing registry. Weak pointer. 128 // The backing registry. Weak pointer.
119 WebIntentsRegistry* intents_registry_; 129 WebIntentsRegistry* intents_registry_;
120 130
121 // Separate list of observers that'll get batch updates. 131 // Separate list of observers that'll get batch updates.
122 ObserverList<Observer> intents_observer_list_; 132 ObserverList<Observer> intents_observer_list_;
123 133
124 // Batch update nesting level. Incremented to indicate that we're in 134 // Batch update nesting level. Incremented to indicate that we're in
125 // the middle of a batch update. 135 // the middle of a batch update.
126 int batch_update_; 136 int batch_update_;
137
138 DISALLOW_COPY_AND_ASSIGN(WebIntentsModel);
127 }; 139 };
128 140
129 #endif // CHROME_BROWSER_UI_INTENTS_WEB_INTENTS_MODEL_H_ 141 #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') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698