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

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: Synced 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/extension_service.h"
9 #include "chrome/browser/extensions/extension_suggested_link.h"
10 #include "chrome/browser/extensions/extension_suggested_links_manager.h"
11 #include "chrome/browser/profiles/profile.h"
12
13 namespace {
14 const char kLinkTextKey[] = "linkText";
15 const char kLinkUrlKey[] = "linkUrl";
16 const char kScoreKey[] = "score";
17 } // anonymous namespace
18
19 namespace extensions {
20
21 bool DiscoverySuggestFunction::RunImpl() {
22 if (!include_incognito() && profile_->IsOffTheRecord()) {
23 error_ = extension_misc::kAppNotificationsIncognitoError;
24 return false;
25 }
26
27 DictionaryValue* details;
28 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
Aaron Boodman 2012/05/11 21:06:46 Use JSONSchemaCompiler to parse arguments. See ala
beaudoin 2012/05/14 23:28:02 Done.
29 EXTENSION_FUNCTION_VALIDATE(details != NULL);
30
31 // TODO(beaudoin): Transform into a GURL right here.
32 std::string link_url;
33 EXTENSION_FUNCTION_VALIDATE(details->GetString(kLinkUrlKey, &link_url));
34
35 std::string link_text;
36 EXTENSION_FUNCTION_VALIDATE(details->GetString(kLinkTextKey, &link_text));
37
38 double score = 1.0;
39 if (details->HasKey(kScoreKey))
40 EXTENSION_FUNCTION_VALIDATE(details->GetDouble(kScoreKey, &score));
41
42 ExtensionSuggestedLinksManager* manager =
43 profile()->GetExtensionService()->suggested_link_manager();
44
45 manager->Add(extension_id(), new ExtensionSuggestedLink(link_url, link_text,
Aaron Boodman 2012/05/11 21:06:46 Wrapping looks wrong. I think 'new ' should start
beaudoin 2012/05/12 03:16:29 Done.
46 score));
47
48 return true;
49 }
50
51 bool DiscoveryClearSuggestionFunction::RunImpl() {
52 if (!include_incognito() && profile_->IsOffTheRecord()) {
53 error_ = extension_misc::kAppNotificationsIncognitoError;
54 return false;
55 }
56
57 // TODO(beaudoin): Transform into a GURL right here.
58 std::string link_url;
59 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &link_url));
60
61 ExtensionSuggestedLinksManager* manager =
62 profile()->GetExtensionService()->suggested_link_manager();
63
64 manager->Clear(extension_id(), link_url);
65
66 return true;
67 }
68
69 bool DiscoveryClearAllSuggestionsFunction::RunImpl() {
70 if (!include_incognito() && profile_->IsOffTheRecord()) {
71 error_ = extension_misc::kAppNotificationsIncognitoError;
72 return false;
73 }
74
75 ExtensionSuggestedLinksManager* manager =
76 profile()->GetExtensionService()->suggested_link_manager();
77
78 manager->ClearAll(extension_id());
79
80 return true;
81 }
82
83 } // namespace extensions
84
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698