OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/extensions/api/declarative_content/declarative_content_
is_bookmarked_condition_tracker.h" | 5 #include "chrome/browser/extensions/api/declarative_content/declarative_content_
is_bookmarked_condition_tracker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" |
8 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
9 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
10 #include "base/values.h" | 11 #include "base/values.h" |
11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
12 #include "chrome/browser/extensions/api/declarative_content/content_constants.h" | 13 #include "chrome/browser/extensions/api/declarative_content/content_constants.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "components/bookmarks/browser/bookmark_model.h" | 15 #include "components/bookmarks/browser/bookmark_model.h" |
15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
16 #include "extensions/common/permissions/permissions_data.h" | 17 #include "extensions/common/permissions/permissions_data.h" |
17 | 18 |
(...skipping 18 matching lines...) Expand all Loading... |
36 | 37 |
37 DeclarativeContentIsBookmarkedPredicate:: | 38 DeclarativeContentIsBookmarkedPredicate:: |
38 ~DeclarativeContentIsBookmarkedPredicate() { | 39 ~DeclarativeContentIsBookmarkedPredicate() { |
39 } | 40 } |
40 | 41 |
41 bool DeclarativeContentIsBookmarkedPredicate::IsIgnored() const { | 42 bool DeclarativeContentIsBookmarkedPredicate::IsIgnored() const { |
42 return !HasBookmarkAPIPermission(extension_.get()); | 43 return !HasBookmarkAPIPermission(extension_.get()); |
43 } | 44 } |
44 | 45 |
45 // static | 46 // static |
46 scoped_ptr<DeclarativeContentIsBookmarkedPredicate> | 47 std::unique_ptr<DeclarativeContentIsBookmarkedPredicate> |
47 DeclarativeContentIsBookmarkedPredicate::Create( | 48 DeclarativeContentIsBookmarkedPredicate::Create( |
48 ContentPredicateEvaluator* evaluator, | 49 ContentPredicateEvaluator* evaluator, |
49 const Extension* extension, | 50 const Extension* extension, |
50 const base::Value& value, | 51 const base::Value& value, |
51 std::string* error) { | 52 std::string* error) { |
52 bool is_bookmarked = false; | 53 bool is_bookmarked = false; |
53 if (value.GetAsBoolean(&is_bookmarked)) { | 54 if (value.GetAsBoolean(&is_bookmarked)) { |
54 if (!HasBookmarkAPIPermission(extension)) { | 55 if (!HasBookmarkAPIPermission(extension)) { |
55 *error = kIsBookmarkedRequiresBookmarkPermission; | 56 *error = kIsBookmarkedRequiresBookmarkPermission; |
56 return scoped_ptr<DeclarativeContentIsBookmarkedPredicate>(); | 57 return std::unique_ptr<DeclarativeContentIsBookmarkedPredicate>(); |
57 } else { | 58 } else { |
58 return make_scoped_ptr( | 59 return base::WrapUnique(new DeclarativeContentIsBookmarkedPredicate( |
59 new DeclarativeContentIsBookmarkedPredicate(evaluator, extension, | 60 evaluator, extension, is_bookmarked)); |
60 is_bookmarked)); | |
61 } | 61 } |
62 } else { | 62 } else { |
63 *error = base::StringPrintf(kInvalidTypeOfParameter, | 63 *error = base::StringPrintf(kInvalidTypeOfParameter, |
64 declarative_content_constants::kIsBookmarked); | 64 declarative_content_constants::kIsBookmarked); |
65 return scoped_ptr<DeclarativeContentIsBookmarkedPredicate>(); | 65 return std::unique_ptr<DeclarativeContentIsBookmarkedPredicate>(); |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 ContentPredicateEvaluator* | 69 ContentPredicateEvaluator* |
70 DeclarativeContentIsBookmarkedPredicate::GetEvaluator() const { | 70 DeclarativeContentIsBookmarkedPredicate::GetEvaluator() const { |
71 return evaluator_; | 71 return evaluator_; |
72 } | 72 } |
73 | 73 |
74 DeclarativeContentIsBookmarkedPredicate:: | 74 DeclarativeContentIsBookmarkedPredicate:: |
75 DeclarativeContentIsBookmarkedPredicate( | 75 DeclarativeContentIsBookmarkedPredicate( |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 161 |
162 DeclarativeContentIsBookmarkedConditionTracker:: | 162 DeclarativeContentIsBookmarkedConditionTracker:: |
163 ~DeclarativeContentIsBookmarkedConditionTracker() { | 163 ~DeclarativeContentIsBookmarkedConditionTracker() { |
164 } | 164 } |
165 | 165 |
166 std::string DeclarativeContentIsBookmarkedConditionTracker:: | 166 std::string DeclarativeContentIsBookmarkedConditionTracker:: |
167 GetPredicateApiAttributeName() const { | 167 GetPredicateApiAttributeName() const { |
168 return declarative_content_constants::kIsBookmarked; | 168 return declarative_content_constants::kIsBookmarked; |
169 } | 169 } |
170 | 170 |
171 scoped_ptr<const ContentPredicate> | 171 std::unique_ptr<const ContentPredicate> |
172 DeclarativeContentIsBookmarkedConditionTracker::CreatePredicate( | 172 DeclarativeContentIsBookmarkedConditionTracker::CreatePredicate( |
173 const Extension* extension, | 173 const Extension* extension, |
174 const base::Value& value, | 174 const base::Value& value, |
175 std::string* error) { | 175 std::string* error) { |
176 return DeclarativeContentIsBookmarkedPredicate::Create(this, extension, value, | 176 return DeclarativeContentIsBookmarkedPredicate::Create(this, extension, value, |
177 error); | 177 error); |
178 } | 178 } |
179 | 179 |
180 // We don't have any centralized state to update for new predicates, so we don't | 180 // We don't have any centralized state to update for new predicates, so we don't |
181 // need to take any action here or in StopTrackingPredicates(). | 181 // need to take any action here or in StopTrackingPredicates(). |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 per_web_contents_tracker_.erase(contents); | 279 per_web_contents_tracker_.erase(contents); |
280 } | 280 } |
281 | 281 |
282 void DeclarativeContentIsBookmarkedConditionTracker:: | 282 void DeclarativeContentIsBookmarkedConditionTracker:: |
283 UpdateAllPerWebContentsTrackers() { | 283 UpdateAllPerWebContentsTrackers() { |
284 for (const auto& web_contents_tracker_pair : per_web_contents_tracker_) | 284 for (const auto& web_contents_tracker_pair : per_web_contents_tracker_) |
285 web_contents_tracker_pair.second->UpdateState(false); | 285 web_contents_tracker_pair.second->UpdateState(false); |
286 } | 286 } |
287 | 287 |
288 } // namespace extensions | 288 } // namespace extensions |
OLD | NEW |