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

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: Now using IDL and a ProfileKeyedService. 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/extension_suggested_link.h"
9 #include "chrome/browser/extensions/api/discovery/extension_suggested_links_mana ger.h"
10 #include "chrome/browser/extensions/api/discovery/extension_suggested_links_mana ger_factory.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 } // anonymous namespace
Aaron Boodman 2012/05/15 00:07:43 Typically this comment just says 'namespace' not '
beaudoin 2012/05/16 16:56:16 Done.
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 ExtensionSuggestedLinksManager* manager =
38 ExtensionSuggestedLinksManagerFactory::GetForProfile(profile());
39
40 manager->Add(extension_id(), new ExtensionSuggestedLink(
41 params->details.link_url, params->details.link_text, score));
42
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 ExtensionSuggestedLinksManager* manager =
52 ExtensionSuggestedLinksManagerFactory::GetForProfile(profile());
53
54 manager->Clear(extension_id(), params->link_url);
55
56 return true;
57 }
58
59 bool DiscoveryClearAllSuggestionsFunction::RunImpl() {
60 ExtensionSuggestedLinksManager* manager =
61 ExtensionSuggestedLinksManagerFactory::GetForProfile(profile());
62
63 manager->ClearAll(extension_id());
64
65 return true;
66 }
67
68 } // namespace extensions
69
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698