OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_UI_INTENTS_INTENTS_MODEL_H_ | |
6 #define CHROME_BROWSER_UI_INTENTS_INTENTS_MODEL_H_ | |
7 #pragma once | |
8 | |
9 #include "base/values.h" | |
10 #include "chrome/browser/intents/web_intents_registry.h" | |
11 #include "ui/base/models/tree_node_model.h" | |
12 | |
13 class WebIntentsRegistry; | |
14 | |
15 // The tree structure is a TYPE_ROOT node with title="", | |
16 // children are TYPE_ORIGIN nodes with title=origin, whose | |
17 // children are TYPE_SERVICE nodes with title=origin, and | |
18 // will be of type ServiceTreeNode with data on individual | |
19 // services. | |
20 class IntentsTreeNode : public ui::TreeNode<IntentsTreeNode> { | |
21 public: | |
22 IntentsTreeNode() | |
23 : ui::TreeNode<IntentsTreeNode>(string16()), | |
24 type_(TYPE_ROOT) {} | |
25 | |
26 explicit IntentsTreeNode(const string16& title) | |
27 : ui::TreeNode<IntentsTreeNode>(title), | |
28 type_(TYPE_ORIGIN) {} | |
29 | |
30 virtual ~IntentsTreeNode() {} | |
31 | |
32 enum NodeType { | |
33 TYPE_ROOT, | |
34 TYPE_ORIGIN, | |
35 TYPE_SERVICE, | |
36 }; | |
37 | |
38 NodeType Type() const { return type_; } | |
39 | |
40 protected: | |
41 IntentsTreeNode(const string16& title, NodeType type) | |
42 : ui::TreeNode<IntentsTreeNode>(title), | |
43 type_(type) {} | |
44 | |
45 private: | |
46 NodeType type_; | |
47 }; | |
48 | |
49 // Tree node representing particular services presented by an origin. | |
50 class ServiceTreeNode : public IntentsTreeNode { | |
51 public: | |
52 explicit ServiceTreeNode(const string16& title) | |
53 : IntentsTreeNode(title, IntentsTreeNode::TYPE_SERVICE) {} | |
54 virtual ~ServiceTreeNode() {} | |
55 | |
56 const string16& ServiceName() const { return service_name_; } | |
57 const string16& ServiceUrl() const { return service_url_; } | |
58 const string16& IconUrl() const { return icon_url_; } | |
59 const string16& Action() const { return action_; } | |
60 const base::ListValue& Types() const { return types_; } | |
61 bool IsBlocked() const { return blocked_; } | |
62 bool IsDisabled() const { return disabled_; } | |
63 | |
64 void SetServiceName(string16 name) { service_name_ = name; } | |
65 void SetServiceUrl(string16 url) { service_url_ = url; } | |
66 void SetIconUrl(string16 url) { icon_url_ = url; } | |
67 void SetAction(string16 action) { action_ = action; } | |
68 void AddType(string16 type) { types_.Append(Value::CreateStringValue(type)); } | |
69 void SetBlocked(bool blocked) { blocked_ = blocked; } | |
70 void SetDisabled(bool disabled) { disabled_ = disabled; } | |
71 | |
72 private: | |
73 string16 service_name_; | |
74 string16 icon_url_; | |
75 string16 service_url_; | |
76 string16 action_; | |
77 base::ListValue types_; | |
78 | |
79 // TODO(gbillock): these are kind of a placeholder for exceptions data. | |
80 bool blocked_; | |
81 bool disabled_; | |
82 }; | |
83 | |
84 // UI-backing tree model of the data in the WebIntentsRegistry. | |
85 class IntentsModel : public ui::TreeNodeModel<IntentsTreeNode>, | |
86 public WebIntentsRegistry::Consumer { | |
87 public: | |
88 // Because nodes are fetched in a background thread, they are not | |
89 // present at the time the Model is created. The Model then notifies its | |
90 // observers for every item added. | |
91 class Observer : public ui::TreeModelObserver { | |
92 public: | |
93 virtual void TreeModelBeginBatch(IntentsModel* model) {} | |
94 virtual void TreeModelEndBatch(IntentsModel* model) {} | |
95 }; | |
96 | |
97 explicit IntentsModel(WebIntentsRegistry* intents_registry); | |
98 virtual ~IntentsModel() {} | |
99 | |
100 void AddIntentsTreeObserver(Observer* observer); | |
101 void RemoveIntentsTreeObserver(Observer* observer); | |
102 | |
103 string16 GetTreeNodeId(IntentsTreeNode* node); | |
104 IntentsTreeNode* GetTreeNode(std::string path_id); | |
105 void GetChildNodeList(IntentsTreeNode* parent, int start, int count, | |
106 base::ListValue* nodes); | |
107 void GetIntentsTreeNodeDictionary(const IntentsTreeNode& node, | |
108 base::DictionaryValue* dict); | |
109 | |
110 virtual void OnIntentsQueryDone( | |
111 WebIntentsRegistry::QueryID query_id, | |
112 const std::vector<WebIntentData>& intents) OVERRIDE; | |
113 | |
114 private: | |
115 // Loads the data model from the WebIntentsRegistry. | |
116 // TODO(gbillock): need an observer on that to absorb async updates? | |
117 void LoadModel(); | |
118 | |
119 // Do batch-specific notifies for updates coming from the LoadModel. | |
120 void NotifyObserverBeginBatch(); | |
121 void NotifyObserverEndBatch(); | |
122 | |
123 // The backing registry. Not owned. | |
James Hawkins
2011/08/17 22:50:29
s/Not owned/Weak pointer/
Greg Billock
2011/08/18 17:36:58
Done.
| |
124 WebIntentsRegistry* intents_registry_; | |
125 | |
126 // Separate list of observers that'll get batch updates. | |
127 ObserverList<Observer> intents_observer_list_; | |
128 | |
129 // Batch update nesting level. Incremented to indicate that we're in | |
130 // the middle of a batch update. | |
131 int batch_update_; | |
132 }; | |
133 | |
134 #endif // CHROME_BROWSER_UI_INTENTS_INTENTS_MODEL_H_ | |
OLD | NEW |