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 #include "chrome/browser/ui/intents/web_intents_model.h" | 5 #include "chrome/browser/ui/intents/web_intents_model.h" |
| 6 |
6 #include "base/string_split.h" | 7 #include "base/string_split.h" |
7 #include "base/string_util.h" | 8 #include "base/string_util.h" |
8 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/intents/default_web_intent_service.h" | |
11 #include "chrome/browser/intents/web_intents_registry.h" | 11 #include "chrome/browser/intents/web_intents_registry.h" |
12 | 12 |
13 WebIntentsTreeNode::WebIntentsTreeNode() | 13 WebIntentsTreeNode::WebIntentsTreeNode() |
14 : ui::TreeNode<WebIntentsTreeNode>(string16()), | 14 : ui::TreeNode<WebIntentsTreeNode>(string16()), |
15 type_(TYPE_ROOT) {} | 15 type_(TYPE_ROOT) {} |
16 | 16 |
17 WebIntentsTreeNode::WebIntentsTreeNode(const string16& title) | 17 WebIntentsTreeNode::WebIntentsTreeNode(const string16& title) |
18 : ui::TreeNode<WebIntentsTreeNode>(title), | 18 : ui::TreeNode<WebIntentsTreeNode>(title), |
19 type_(TYPE_ORIGIN) {} | 19 type_(TYPE_ORIGIN) {} |
20 | 20 |
21 WebIntentsTreeNode::~WebIntentsTreeNode() {} | 21 WebIntentsTreeNode::~WebIntentsTreeNode() {} |
22 | 22 |
23 ServiceTreeNode::ServiceTreeNode(const string16& title) | 23 ServiceTreeNode::ServiceTreeNode(const string16& title) |
24 : WebIntentsTreeNode(title, WebIntentsTreeNode::TYPE_SERVICE), | 24 : WebIntentsTreeNode(title, WebIntentsTreeNode::TYPE_SERVICE), |
25 blocked_(false), | 25 blocked_(false), |
26 disabled_(false) {} | 26 disabled_(false) {} |
27 | 27 |
28 ServiceTreeNode::~ServiceTreeNode() {} | 28 ServiceTreeNode::~ServiceTreeNode() {} |
29 | 29 |
30 WebIntentsModel::WebIntentsModel(WebIntentsRegistry* intents_registry) | 30 WebIntentsModel::WebIntentsModel(WebIntentsRegistry* intents_registry) |
31 : ui::TreeNodeModel<WebIntentsTreeNode>(new WebIntentsTreeNode()), | 31 : ui::TreeNodeModel<WebIntentsTreeNode>(new WebIntentsTreeNode()), |
32 intents_registry_(intents_registry), | 32 intents_registry_(intents_registry), |
33 batch_update_(0) { | 33 batch_update_(0) { |
34 LoadModel(); | 34 LoadModel(); |
35 } | 35 } |
36 | 36 |
(...skipping 14 matching lines...) Expand all Loading... |
51 string16 WebIntentsModel::GetTreeNodeId(WebIntentsTreeNode* node) { | 51 string16 WebIntentsModel::GetTreeNodeId(WebIntentsTreeNode* node) { |
52 if (node->Type() == WebIntentsTreeNode::TYPE_ORIGIN) | 52 if (node->Type() == WebIntentsTreeNode::TYPE_ORIGIN) |
53 return node->GetTitle(); | 53 return node->GetTitle(); |
54 | 54 |
55 // TODO(gbillock): handle TYPE_SERVICE when/if we ever want to do | 55 // TODO(gbillock): handle TYPE_SERVICE when/if we ever want to do |
56 // specific managing of them. | 56 // specific managing of them. |
57 | 57 |
58 return string16(); | 58 return string16(); |
59 } | 59 } |
60 | 60 |
61 WebIntentsTreeNode* WebIntentsModel::GetTreeNode(std::string path_id) { | 61 WebIntentsTreeNode* WebIntentsModel::GetTreeNode(const std::string& path_id) { |
62 if (path_id.empty()) | 62 if (path_id.empty()) |
63 return GetRoot(); | 63 return GetRoot(); |
64 | 64 |
65 std::vector<std::string> node_ids; | 65 std::vector<std::string> node_ids; |
66 base::SplitString(path_id, ',', &node_ids); | 66 base::SplitString(path_id, ',', &node_ids); |
67 | 67 |
68 for (int i = 0; i < GetRoot()->child_count(); ++i) { | 68 for (int i = 0; i < GetRoot()->child_count(); ++i) { |
69 WebIntentsTreeNode* node = GetRoot()->GetChild(i); | 69 WebIntentsTreeNode* node = GetRoot()->GetChild(i); |
70 if (UTF16ToUTF8(node->GetTitle()) == node_ids[0]) { | 70 if (UTF16ToUTF8(node->GetTitle()) == node_ids[0]) { |
71 if (node_ids.size() == 1) | 71 if (node_ids.size() == 1) |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 166 |
167 void WebIntentsModel::NotifyObserverEndBatch() { | 167 void WebIntentsModel::NotifyObserverEndBatch() { |
168 // Only notify the observers if this is the outermost call to EndBatch() if | 168 // Only notify the observers if this is the outermost call to EndBatch() if |
169 // called in a nested manner. | 169 // called in a nested manner. |
170 if (--batch_update_ == 0) { | 170 if (--batch_update_ == 0) { |
171 FOR_EACH_OBSERVER(Observer, | 171 FOR_EACH_OBSERVER(Observer, |
172 intents_observer_list_, | 172 intents_observer_list_, |
173 TreeModelEndBatch(this)); | 173 TreeModelEndBatch(this)); |
174 } | 174 } |
175 } | 175 } |
OLD | NEW |