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

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: Get rid of message-passing changes. 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, 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 {
James Hawkins 2011/08/17 21:34:15 Can this just be a struct? It seems it's only gett
Greg Billock 2011/08/17 22:44:02 It needs to fit into the TreeNode<T> system, at le
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 class IntentsModel : public ui::TreeNodeModel<IntentsTreeNode>,
James Hawkins 2011/08/17 21:34:15 Document the class.
Greg Billock 2011/08/17 22:44:02 Done.
85 public WebIntentsRegistry::Consumer {
86 public:
87 // Because nodes are fetched in a background thread, they are not
88 // present at the time the Model is created. The Model then notifies its
89 // observers for every item added.
90 class Observer : public ui::TreeModelObserver {
91 public:
92 virtual void TreeModelBeginBatch(IntentsModel* model) {}
93 virtual void TreeModelEndBatch(IntentsModel* model) {}
94 };
95
96 explicit IntentsModel(WebIntentsRegistry* intents_registry);
97 virtual ~IntentsModel() {}
98
99 void AddIntentsTreeObserver(Observer* observer);
100 void RemoveIntentsTreeObserver(Observer* observer);
101
102 string16 GetTreeNodeId(IntentsTreeNode* node);
103 IntentsTreeNode* GetTreeNode(std::string path_id);
104 void GetChildNodeList(IntentsTreeNode* parent, int start, int count,
105 base::ListValue* nodes);
106 void GetIntentsTreeNodeDictionary(const IntentsTreeNode& node,
107 base::DictionaryValue* dict);
108
109 virtual void OnIntentsQueryDone(
110 WebIntentsRegistry::QueryID query_id,
111 const std::vector<WebIntentData>& intents) OVERRIDE;
112
113 private:
114 void LoadModel();
James Hawkins 2011/08/17 21:34:15 These are not self-documenting, please document.
Greg Billock 2011/08/17 22:44:02 Done.
115 void NotifyObserverBeginBatch();
116 void NotifyObserverEndBatch();
117
118 WebIntentsRegistry* intents_registry_;
James Hawkins 2011/08/17 21:34:15 Always document all vars. Note ownership.
Greg Billock 2011/08/17 22:44:02 Done.
119 int batch_update_;
120 ObserverList<Observer> intents_observer_list_;
121 };
122
123 #endif // CHROME_BROWSER_UI_INTENTS_INTENTS_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698