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

Side by Side Diff: chrome/browser/extensions/api/discovery/discovery_api.cc

Issue 10391034: Scaffolding for an experimental discovery API letting users inject links in the recommended pane of… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Answered review comments from PatchSet 4. Created 8 years, 7 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) 2012 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 #include "chrome/browser/extensions/api/discovery/discovery_api.h"
6
7 #include "base/values.h"
8 #include "chrome/browser/extensions/api/discovery/suggested_link.h"
9 #include "chrome/browser/extensions/api/discovery/suggested_links_registry.h"
10 #include "chrome/browser/extensions/api/discovery/suggested_links_registry_facto ry.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/extensions/api/experimental_discovery.h"
13 #include "chrome/common/extensions/extension_error_utils.h"
14
15 namespace discovery = extensions::api::experimental_discovery;
16
17 namespace {
18 const char kInvalidScore[] = "Invalid score, must be between 0 and 1.";
19 } // namespace
20
21 namespace extensions {
22
23 bool DiscoverySuggestFunction::RunImpl() {
24 scoped_ptr<discovery::Suggest::Params> params(
25 discovery::Suggest::Params::Create(*args_));
26 EXTENSION_FUNCTION_VALIDATE(params.get());
27
28 double score = 1.0;
29 if (params->details.score != NULL) {
30 score = *params->details.score;
31 if (score < 0.0 || score > 1.0) {
32 error_ = kInvalidScore;
33 return false;
34 }
35 }
36
37 extensions::SuggestedLinksRegistry* registry =
38 extensions::SuggestedLinksRegistryFactory::GetForProfile(profile());
39 scoped_ptr<extensions::SuggestedLink> suggested_link(
40 new extensions::SuggestedLink(params->details.link_url,
41 params->details.link_text, score));
42 registry->Add(extension_id(), suggested_link.Pass());
43 return true;
44 }
45
46 bool DiscoveryRemoveSuggestionFunction::RunImpl() {
47 scoped_ptr<discovery::RemoveSuggestion::Params> params(
48 discovery::RemoveSuggestion::Params::Create(*args_));
49 EXTENSION_FUNCTION_VALIDATE(params.get());
50
51 extensions::SuggestedLinksRegistry* registry =
52 extensions::SuggestedLinksRegistryFactory::GetForProfile(profile());
53 registry->Remove(extension_id(), params->link_url);
54
55 return true;
56 }
57
58 bool DiscoveryClearAllSuggestionsFunction::RunImpl() {
59 extensions::SuggestedLinksRegistry* registry =
60 extensions::SuggestedLinksRegistryFactory::GetForProfile(profile());
61 registry->ClearAll(extension_id());
62
63 return true;
64 }
65
66 } // namespace extensions
67
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/discovery/discovery_api.h ('k') | chrome/browser/extensions/api/discovery/suggested_link.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698