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