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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/discovery/discovery_api.cc
diff --git a/chrome/browser/extensions/api/discovery/discovery_api.cc b/chrome/browser/extensions/api/discovery/discovery_api.cc
new file mode 100644
index 0000000000000000000000000000000000000000..53943fdff138d535cc6ce7291264f0745793647c
--- /dev/null
+++ b/chrome/browser/extensions/api/discovery/discovery_api.cc
@@ -0,0 +1,84 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/discovery/discovery_api.h"
+
+#include "base/values.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_suggested_link.h"
+#include "chrome/browser/extensions/extension_suggested_links_manager.h"
+#include "chrome/browser/profiles/profile.h"
+
+namespace {
+const char kLinkTextKey[] = "linkText";
+const char kLinkUrlKey[] = "linkUrl";
+const char kScoreKey[] = "score";
+} // anonymous namespace
+
+namespace extensions {
+
+bool DiscoverySuggestFunction::RunImpl() {
+ if (!include_incognito() && profile_->IsOffTheRecord()) {
+ error_ = extension_misc::kAppNotificationsIncognitoError;
+ return false;
+ }
+
+ DictionaryValue* details;
+ 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.
+ EXTENSION_FUNCTION_VALIDATE(details != NULL);
+
+ // TODO(beaudoin): Transform into a GURL right here.
+ std::string link_url;
+ EXTENSION_FUNCTION_VALIDATE(details->GetString(kLinkUrlKey, &link_url));
+
+ std::string link_text;
+ EXTENSION_FUNCTION_VALIDATE(details->GetString(kLinkTextKey, &link_text));
+
+ double score = 1.0;
+ if (details->HasKey(kScoreKey))
+ EXTENSION_FUNCTION_VALIDATE(details->GetDouble(kScoreKey, &score));
+
+ ExtensionSuggestedLinksManager* manager =
+ profile()->GetExtensionService()->suggested_link_manager();
+
+ 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.
+ score));
+
+ return true;
+}
+
+bool DiscoveryClearSuggestionFunction::RunImpl() {
+ if (!include_incognito() && profile_->IsOffTheRecord()) {
+ error_ = extension_misc::kAppNotificationsIncognitoError;
+ return false;
+ }
+
+ // TODO(beaudoin): Transform into a GURL right here.
+ std::string link_url;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &link_url));
+
+ ExtensionSuggestedLinksManager* manager =
+ profile()->GetExtensionService()->suggested_link_manager();
+
+ manager->Clear(extension_id(), link_url);
+
+ return true;
+}
+
+bool DiscoveryClearAllSuggestionsFunction::RunImpl() {
+ if (!include_incognito() && profile_->IsOffTheRecord()) {
+ error_ = extension_misc::kAppNotificationsIncognitoError;
+ return false;
+ }
+
+ ExtensionSuggestedLinksManager* manager =
+ profile()->GetExtensionService()->suggested_link_manager();
+
+ manager->ClearAll(extension_id());
+
+ return true;
+}
+
+} // namespace extensions
+

Powered by Google App Engine
This is Rietveld 408576698