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

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

Issue 7624012: First pass on intents options UI. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 4 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
(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, but
18 // all the service data stored in other node fields.
19 class IntentsTreeNode : public ui::TreeNode<IntentsTreeNode> {
20 public:
21 IntentsTreeNode()
22 : ui::TreeNode<IntentsTreeNode>(string16()),
23 type_(TYPE_ROOT) {}
24
25 explicit IntentsTreeNode(const string16& title)
26 : ui::TreeNode<IntentsTreeNode>(title),
27 type_(TYPE_ORIGIN) {}
28
29 virtual ~IntentsTreeNode() {}
30
31 enum NodeType {
32 TYPE_ROOT,
33 TYPE_ORIGIN,
34 TYPE_SERVICE,
35 };
36
37 NodeType Type() const { return type_; }
38
39 protected:
40 IntentsTreeNode(const string16& title, NodeType type)
41 : ui::TreeNode<IntentsTreeNode>(title),
42 type_(type) {}
43
44 private:
45 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
46 };
47
48 class ServiceTreeNode : public IntentsTreeNode {
49 public:
50 explicit ServiceTreeNode(const string16& title)
51 : IntentsTreeNode(title, IntentsTreeNode::TYPE_SERVICE) {}
52 virtual ~ServiceTreeNode() {}
53
54 const string16& ServiceName() const { return service_name_; }
55 const string16& ServiceUrl() const { return service_url_; }
56 const string16& IconUrl() const { return icon_url_; }
57 const string16& Action() const { return action_; }
58 const base::ListValue& Types() const { return types_; }
59 bool IsBlocked() const { return blocked_; }
60 bool IsDisabled() const { return disabled_; }
61
62 void SetServiceName(string16 name) { service_name_ = name; }
63 void SetServiceUrl(string16 url) { service_url_ = url; }
64 void SetIconUrl(string16 url) { icon_url_ = url; }
65 void SetAction(string16 action) { action_ = action; }
66 void AddType(string16 type) { types_.Append(Value::CreateStringValue(type)); }
67 void SetBlocked(bool blocked) { blocked_ = blocked; }
68 void SetDisabled(bool disabled) { disabled_ = disabled; }
69
70 private:
71 string16 service_name_;
72 string16 icon_url_;
73 string16 service_url_;
74 string16 action_;
75 base::ListValue types_;
76 bool blocked_;
77 bool disabled_;
78 };
79
80 class IntentsModel : public ui::TreeNodeModel<IntentsTreeNode>,
81 public WebIntentsRegistry::Consumer {
82 public:
83 // Because nodes are fetched in a background thread, they are not
84 // present at the time the Model is created. The Model then notifies its
85 // observers for every item added.
86 class Observer : public ui::TreeModelObserver {
87 public:
88 virtual void TreeModelBeginBatch(IntentsModel* model) {}
89 virtual void TreeModelEndBatch(IntentsModel* model) {}
90 };
91
92 explicit IntentsModel(WebIntentsRegistry* intents_registry);
93 virtual ~IntentsModel() {}
94
95 void AddIntentsTreeObserver(Observer* observer);
96 void RemoveIntentsTreeObserver(Observer* observer);
97
98 string16 GetTreeNodeId(IntentsTreeNode* node);
99 IntentsTreeNode* GetTreeNode(std::string path_id);
100 void GetChildNodeList(IntentsTreeNode* parent, int start, int count,
101 base::ListValue* nodes);
102 void GetIntentsTreeNodeDictionary(const IntentsTreeNode& node,
103 base::DictionaryValue* dict);
104
105 virtual void OnIntentsQueryDone(
106 WebIntentsRegistry::QueryID query_id,
107 const std::vector<WebIntentData>& intents) OVERRIDE;
108
109 private:
110 void LoadModel();
111 void NotifyObserverBeginBatch();
112 void NotifyObserverEndBatch();
113
114 WebIntentsRegistry* intents_registry_;
115 int batch_update_;
116 ObserverList<Observer> intents_observer_list_;
117 };
118
119 #endif // CHROME_BROWSER_UI_INTENTS_INTENTS_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698