Chromium Code Reviews| Index: chrome/browser/ui/intents/intents_model.h |
| diff --git a/chrome/browser/ui/intents/intents_model.h b/chrome/browser/ui/intents/intents_model.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..64eff897a896dbb52f0e6d0afb3e0aa68aea54c0 |
| --- /dev/null |
| +++ b/chrome/browser/ui/intents/intents_model.h |
| @@ -0,0 +1,119 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_UI_INTENTS_INTENTS_MODEL_H_ |
| +#define CHROME_BROWSER_UI_INTENTS_INTENTS_MODEL_H_ |
| +#pragma once |
| + |
| +#include "base/values.h" |
| +#include "chrome/browser/intents/web_intents_registry.h" |
| +#include "ui/base/models/tree_node_model.h" |
| + |
| +class WebIntentsRegistry; |
| + |
| +// The tree structure is a TYPE_ROOT node with title="", |
| +// children are TYPE_ORIGIN nodes with title=origin, whose |
| +// children are TYPE_SERVICE nodes with title=origin, but |
| +// all the service data stored in other node fields. |
| +class IntentsTreeNode : public ui::TreeNode<IntentsTreeNode> { |
| + public: |
| + IntentsTreeNode() |
| + : ui::TreeNode<IntentsTreeNode>(string16()), |
| + type_(TYPE_ROOT) {} |
| + |
| + explicit IntentsTreeNode(const string16& title) |
| + : ui::TreeNode<IntentsTreeNode>(title), |
| + type_(TYPE_ORIGIN) {} |
| + |
| + virtual ~IntentsTreeNode() {} |
| + |
| + enum NodeType { |
| + TYPE_ROOT, |
| + TYPE_ORIGIN, |
| + TYPE_SERVICE, |
| + }; |
| + |
| + NodeType Type() const { return type_; } |
| + |
| + protected: |
| + IntentsTreeNode(const string16& title, NodeType type) |
| + : ui::TreeNode<IntentsTreeNode>(title), |
| + type_(type) {} |
| + |
| + private: |
| + NodeType type_; |
|
James Hawkins
2011/08/17 03:18:39
All classes, member vars, methods need documentati
Greg Billock
2011/08/17 18:49:50
The class doc talks about this TYPE_* structure no
|
| +}; |
| + |
| +class ServiceTreeNode : public IntentsTreeNode { |
| + public: |
| + explicit ServiceTreeNode(const string16& title) |
| + : IntentsTreeNode(title, IntentsTreeNode::TYPE_SERVICE) {} |
| + virtual ~ServiceTreeNode() {} |
| + |
| + const string16& ServiceName() const { return service_name_; } |
| + const string16& ServiceUrl() const { return service_url_; } |
| + const string16& IconUrl() const { return icon_url_; } |
| + const string16& Action() const { return action_; } |
| + const base::ListValue& Types() const { return types_; } |
| + bool IsBlocked() const { return blocked_; } |
| + bool IsDisabled() const { return disabled_; } |
| + |
| + void SetServiceName(string16 name) { service_name_ = name; } |
| + void SetServiceUrl(string16 url) { service_url_ = url; } |
| + void SetIconUrl(string16 url) { icon_url_ = url; } |
| + void SetAction(string16 action) { action_ = action; } |
| + void AddType(string16 type) { types_.Append(Value::CreateStringValue(type)); } |
| + void SetBlocked(bool blocked) { blocked_ = blocked; } |
| + void SetDisabled(bool disabled) { disabled_ = disabled; } |
| + |
| + private: |
| + string16 service_name_; |
| + string16 icon_url_; |
| + string16 service_url_; |
| + string16 action_; |
| + base::ListValue types_; |
| + bool blocked_; |
| + bool disabled_; |
| +}; |
| + |
| +class IntentsModel : public ui::TreeNodeModel<IntentsTreeNode>, |
| + public WebIntentsRegistry::Consumer { |
| + public: |
| + // Because nodes are fetched in a background thread, they are not |
| + // present at the time the Model is created. The Model then notifies its |
| + // observers for every item added. |
| + class Observer : public ui::TreeModelObserver { |
| + public: |
| + virtual void TreeModelBeginBatch(IntentsModel* model) {} |
| + virtual void TreeModelEndBatch(IntentsModel* model) {} |
| + }; |
| + |
| + explicit IntentsModel(WebIntentsRegistry* intents_registry); |
| + virtual ~IntentsModel() {} |
| + |
| + void AddIntentsTreeObserver(Observer* observer); |
| + void RemoveIntentsTreeObserver(Observer* observer); |
| + |
| + string16 GetTreeNodeId(IntentsTreeNode* node); |
| + IntentsTreeNode* GetTreeNode(std::string path_id); |
| + void GetChildNodeList(IntentsTreeNode* parent, int start, int count, |
| + base::ListValue* nodes); |
| + void GetIntentsTreeNodeDictionary(const IntentsTreeNode& node, |
| + base::DictionaryValue* dict); |
| + |
| + virtual void OnIntentsQueryDone( |
| + WebIntentsRegistry::QueryID query_id, |
| + const std::vector<WebIntentData>& intents) OVERRIDE; |
| + |
| + private: |
| + void LoadModel(); |
| + void NotifyObserverBeginBatch(); |
| + void NotifyObserverEndBatch(); |
| + |
| + WebIntentsRegistry* intents_registry_; |
| + int batch_update_; |
| + ObserverList<Observer> intents_observer_list_; |
| +}; |
| + |
| +#endif // CHROME_BROWSER_UI_INTENTS_INTENTS_MODEL_H_ |