summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorgbillock@chromium.org <gbillock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-09 23:19:45 +0000
committergbillock@chromium.org <gbillock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-09 23:19:45 +0000
commit778cf547150c7ae1b7bc238d97844285e65111ef (patch)
tree96cc015c811a43c568321d2ce00a6374902a40c1 /chrome
parentd87b638ae73de94c2bbd59468e0409c91abbe582 (diff)
downloadchromium_src-778cf547150c7ae1b7bc238d97844285e65111ef.zip
chromium_src-778cf547150c7ae1b7bc238d97844285e65111ef.tar.gz
chromium_src-778cf547150c7ae1b7bc238d97844285e65111ef.tar.bz2
Modify schema to include defaulting information.
R=jhawkins@chromium.org,binji@chromium.org,groby@chromium.org BUG=110636 TEST=None yet Review URL: http://codereview.chromium.org/9104018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121330 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/intents/default_web_intent_service.cc10
-rw-r--r--chrome/browser/intents/default_web_intent_service.h41
-rw-r--r--chrome/browser/webdata/web_intents_table.cc129
-rw-r--r--chrome/browser/webdata/web_intents_table.h42
-rw-r--r--chrome/browser/webdata/web_intents_table_unittest.cc54
-rw-r--r--chrome/chrome_browser.gypi2
6 files changed, 262 insertions, 16 deletions
diff --git a/chrome/browser/intents/default_web_intent_service.cc b/chrome/browser/intents/default_web_intent_service.cc
new file mode 100644
index 0000000..c34c974
--- /dev/null
+++ b/chrome/browser/intents/default_web_intent_service.cc
@@ -0,0 +1,10 @@
+// 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/intents/default_web_intent_service.h"
+
+DefaultWebIntentService::DefaultWebIntentService()
+ : url_pattern(URLPattern::SCHEME_ALL), user_date(-1), suppression(0) {}
+
+DefaultWebIntentService::~DefaultWebIntentService() {}
diff --git a/chrome/browser/intents/default_web_intent_service.h b/chrome/browser/intents/default_web_intent_service.h
new file mode 100644
index 0000000..c1962ac
--- /dev/null
+++ b/chrome/browser/intents/default_web_intent_service.h
@@ -0,0 +1,41 @@
+// 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.
+
+#ifndef CHROME_BROWSER_INTENTS_DEFAULT_WEB_INTENT_SERVICE_H_
+#define CHROME_BROWSER_INTENTS_DEFAULT_WEB_INTENT_SERVICE_H_
+
+#include <string>
+
+#include "base/string16.h"
+#include "chrome/common/extensions/url_pattern.h"
+
+// Holds data related to a default settings for web intents service
+// selection. Holds data in a row in the web_intents_defaults table.
+// The key for the table is the |action|, |type|, and |url_pattern|.
+// These describe the action and type of the web intent for which the
+// default is set, and the url prefix (if any) of source pages for
+// which the default applies. The main actionable value is the URL
+// of the service or extension page handling the intent. The |user_date|
+// and |suppression| fields are provided for more intricate post-fetch
+// decisions about whether to use a particular default service.
+struct DefaultWebIntentService {
+ string16 action;
+ string16 type;
+ URLPattern url_pattern;
+
+ // |user_date| holds the offset time when a user set the default.
+ // If the user did not set the default explicitly, is <= 0.
+ int user_date;
+
+ // |suppression| holds a value modeling whether a default is suppressed.
+ // If it has value == 0, the default is active.
+ int suppression;
+
+ std::string service_url;
+
+ DefaultWebIntentService();
+ ~DefaultWebIntentService();
+};
+
+#endif // CHROME_BROWSER_INTENTS_DEFAULT_WEB_INTENT_SERVICE_H_
diff --git a/chrome/browser/webdata/web_intents_table.cc b/chrome/browser/webdata/web_intents_table.cc
index b717ba4..a5a9242 100644
--- a/chrome/browser/webdata/web_intents_table.cc
+++ b/chrome/browser/webdata/web_intents_table.cc
@@ -1,12 +1,17 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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/webdata/web_intents_table.h"
+#include <string>
+#include "base/i18n/case_conversion.h"
#include "base/logging.h"
+#include "base/string_util.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/intents/default_web_intent_service.h"
#include "googleurl/src/gurl.h"
+#include "net/base/mime_util.h"
#include "sql/statement.h"
using webkit_glue::WebIntentServiceData;
@@ -48,21 +53,39 @@ WebIntentsTable::~WebIntentsTable() {
}
bool WebIntentsTable::Init() {
- if (db_->DoesTableExist("web_intents"))
- return true;
-
- if (!db_->Execute("CREATE TABLE web_intents ("
- "service_url LONGVARCHAR,"
- "action VARCHAR,"
- "type VARCHAR,"
- "title VARCHAR,"
- "disposition VARCHAR,"
- "UNIQUE (service_url, action, type))")) {
- return false;
+ if (!db_->DoesTableExist("web_intents")) {
+ if (!db_->Execute("CREATE TABLE web_intents ("
+ "service_url LONGVARCHAR,"
+ "action VARCHAR,"
+ "type VARCHAR,"
+ "title LONGVARCHAR,"
+ "disposition VARCHAR,"
+ "UNIQUE (service_url, action, type))")) {
+ return false;
+ }
+ }
+
+ if (!db_->DoesTableExist("web_intents_defaults")) {
+ if (!db_->Execute("CREATE TABLE web_intents_defaults ("
+ "action VARCHAR,"
+ "type VARCHAR,"
+ "url_pattern LONGVARCHAR,"
+ "user_date INTEGER,"
+ "suppression INTEGER,"
+ "service_url LONGVARCHAR,"
+ "UNIQUE (action, type, url_pattern))")) {
+ return false;
+ }
}
- if (!db_->Execute("CREATE INDEX web_intents_index ON web_intents (action)"))
+ if (!db_->Execute("CREATE INDEX IF NOT EXISTS web_intents_index "
+ "ON web_intents (action)"))
+ return false;
+
+ if (!db_->Execute("CREATE INDEX IF NOT EXISTS web_intents_default_index "
+ "ON web_intents_defaults (action)")) {
return false;
+ }
return true;
}
@@ -141,3 +164,83 @@ bool WebIntentsTable::RemoveWebIntentService(
return s.Run();
}
+
+bool WebIntentsTable::GetDefaultServices(
+ const string16& action,
+ std::vector<DefaultWebIntentService>* default_services) {
+ sql::Statement s(db_->GetUniqueStatement(
+ "SELECT action, type, url_pattern, user_date, suppression, "
+ "service_url FROM web_intents_defaults "
+ "WHERE action=?"));
+ s.BindString16(0, action);
+
+ while (s.Step()) {
+ DefaultWebIntentService entry;
+ entry.action = s.ColumnString16(0);
+ entry.type = s.ColumnString16(1);
+ if (entry.url_pattern.Parse(s.ColumnString(2)) !=
+ URLPattern::PARSE_SUCCESS) {
+ return false;
+ }
+ entry.user_date = s.ColumnInt(3);
+ entry.suppression = s.ColumnInt(4);
+ entry.service_url = s.ColumnString(5);
+
+ default_services->push_back(entry);
+ }
+
+ return s.Succeeded();
+}
+
+bool WebIntentsTable::GetAllDefaultServices(
+ std::vector<DefaultWebIntentService>* default_services) {
+ sql::Statement s(db_->GetUniqueStatement(
+ "SELECT action, type, url_pattern, user_date, suppression, "
+ "service_url FROM web_intents_defaults"));
+
+ while (s.Step()) {
+ DefaultWebIntentService entry;
+ entry.action = s.ColumnString16(0);
+ entry.type = s.ColumnString16(1);
+ if (entry.url_pattern.Parse(s.ColumnString(2)) !=
+ URLPattern::PARSE_SUCCESS) {
+ return false;
+ }
+ entry.user_date = s.ColumnInt(3);
+ entry.suppression = s.ColumnInt(4);
+ entry.service_url = s.ColumnString(5);
+
+ default_services->push_back(entry);
+ }
+
+ return s.Succeeded();
+
+}
+
+bool WebIntentsTable::SetDefaultService(
+ const DefaultWebIntentService& default_service) {
+ sql::Statement s(db_->GetUniqueStatement(
+ "INSERT OR REPLACE INTO web_intents_defaults "
+ "(action, type, url_pattern, user_date, suppression, service_url) "
+ "VALUES (?, ?, ?, ?, ?, ?)"));
+ s.BindString16(0, default_service.action);
+ s.BindString16(1, default_service.type);
+ s.BindString(2, default_service.url_pattern.GetAsString());
+ s.BindInt(3, default_service.user_date);
+ s.BindInt(4, default_service.suppression);
+ s.BindString(5, default_service.service_url);
+
+ return s.Run();
+}
+
+bool WebIntentsTable::RemoveDefaultService(
+ const DefaultWebIntentService& default_service) {
+ sql::Statement s(db_->GetUniqueStatement(
+ "DELETE FROM web_intents_defaults "
+ "WHERE action = ? AND type = ? AND url_pattern = ?"));
+ s.BindString16(0, default_service.action);
+ s.BindString16(1, default_service.type);
+ s.BindString(2, default_service.url_pattern.GetAsString());
+
+ return s.Run();
+}
diff --git a/chrome/browser/webdata/web_intents_table.h b/chrome/browser/webdata/web_intents_table.h
index beb0c19..d97b4f6 100644
--- a/chrome/browser/webdata/web_intents_table.h
+++ b/chrome/browser/webdata/web_intents_table.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -19,6 +19,8 @@ class Connection;
class MetaTable;
}
+struct DefaultWebIntentService;
+
// This class manages the WebIntents table within the SQLite database passed
// to the constructor. It expects the following schema:
//
@@ -26,8 +28,25 @@ class MetaTable;
// service_url URL for service invocation.
// action Name of action provided by the service.
// type MIME type of data accepted by the service.
+// title Title for the service page
+// disposition Either 'window' or 'inline' disposition.
+//
+// Web Intent Services are uniquely identified by the <service_url,action,type>
+// tuple.
+//
+// Also manages the defaults table:
+//
+// web_intents_defaults
+// action Intent action for this default.
+// type Intent type for this default.
+// url_prefix URL prefix for which the default is invoked.
+// user_date Epoch time when the user made this default.
+// suppression Set if the default is (temporarily) suppressed.
+// service_url The URL of a service in the web_intents table.
+// extension_url The URL for an extension handling intents.
+//
+// The defaults are scoped by action, then type, then url prefix.
//
-// Intents are uniquely identified by the <service_url,action,type> tuple.
class WebIntentsTable : public WebDatabaseTable {
public:
WebIntentsTable(sql::Connection* db, sql::MetaTable* meta_table);
@@ -59,6 +78,25 @@ class WebIntentsTable : public WebDatabaseTable {
// exactly.
bool RemoveWebIntentService(const webkit_glue::WebIntentServiceData& service);
+ // Get the default service to be used for the given intent invocation.
+ // If any overlapping defaults are found, they're placed in
+ // |default_services|, otherwise, it is untouched.
+ // Returns true if the method runs successfully, false on database error.
+ bool GetDefaultServices(
+ const string16& action,
+ std::vector<DefaultWebIntentService>* default_services);
+
+ // Get a list of all installed default services.
+ bool GetAllDefaultServices(
+ std::vector<DefaultWebIntentService>* default_services);
+
+ // Set a default service to be used on given intent invocations.
+ bool SetDefaultService(const DefaultWebIntentService& default_service);
+
+ // Removes a default |service| from table - must match the action, type,
+ // and url_prefix parameters exactly.
+ bool RemoveDefaultService(const DefaultWebIntentService& default_service);
+
private:
DISALLOW_COPY_AND_ASSIGN(WebIntentsTable);
};
diff --git a/chrome/browser/webdata/web_intents_table_unittest.cc b/chrome/browser/webdata/web_intents_table_unittest.cc
index 32edcd0..b91317e 100644
--- a/chrome/browser/webdata/web_intents_table_unittest.cc
+++ b/chrome/browser/webdata/web_intents_table_unittest.cc
@@ -1,13 +1,16 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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 <algorithm>
+#include <string>
+#include <vector>
#include "base/file_util.h"
#include "base/scoped_temp_dir.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/intents/default_web_intent_service.h"
#include "chrome/browser/webdata/web_database.h"
#include "chrome/browser/webdata/web_intents_table.h"
#include "chrome/common/chrome_paths.h"
@@ -182,4 +185,53 @@ TEST_F(WebIntentsTableTest, GetByURL) {
ASSERT_EQ(2U, intents.size());
}
+TEST_F(WebIntentsTableTest, DefaultServices) {
+ DefaultWebIntentService default_service;
+ default_service.action = test_action;
+ default_service.type = mime_image;
+ default_service.url_pattern.Parse(test_url.spec());
+ default_service.user_date = 1;
+ default_service.suppression = 4;
+ default_service.service_url = "service_url";
+ ASSERT_TRUE(IntentsTable()->SetDefaultService(default_service));
+
+ default_service.action = test_action_2;
+ ASSERT_TRUE(IntentsTable()->SetDefaultService(default_service));
+
+ std::vector<DefaultWebIntentService> defaults;
+ ASSERT_TRUE(IntentsTable()->GetDefaultServices(ASCIIToUTF16("no_action"),
+ &defaults));
+ EXPECT_EQ(0U, defaults.size());
+
+ ASSERT_TRUE(IntentsTable()->GetDefaultServices(test_action, &defaults));
+ ASSERT_EQ(1U, defaults.size());
+
+ EXPECT_EQ(test_action, defaults[0].action);
+ EXPECT_EQ(mime_image, defaults[0].type);
+ URLPattern test_pattern(URLPattern::SCHEME_HTTP, test_url.spec());
+ EXPECT_EQ(test_pattern, defaults[0].url_pattern);
+ EXPECT_EQ(1, defaults[0].user_date);
+ EXPECT_EQ(4, defaults[0].suppression);
+ EXPECT_EQ("service_url", defaults[0].service_url);
+
+ defaults.clear();
+ ASSERT_TRUE(IntentsTable()->GetAllDefaultServices(&defaults));
+ ASSERT_EQ(2U, defaults.size());
+
+ default_service.action = test_action;
+ IntentsTable()->RemoveDefaultService(default_service);
+
+ defaults.clear();
+ ASSERT_TRUE(IntentsTable()->GetDefaultServices(test_action, &defaults));
+ ASSERT_EQ(0U, defaults.size());
+
+ defaults.clear();
+ ASSERT_TRUE(IntentsTable()->GetDefaultServices(test_action_2, &defaults));
+ ASSERT_EQ(1U, defaults.size());
+
+ defaults.clear();
+ ASSERT_TRUE(IntentsTable()->GetAllDefaultServices(&defaults));
+ ASSERT_EQ(1U, defaults.size());
+}
+
} // namespace
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 734953e..c89732c 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1570,6 +1570,8 @@
'browser/intents/cws_intents_registry.h',
'browser/intents/cws_intents_registry_factory.cc',
'browser/intents/cws_intents_registry_factory.h',
+ 'browser/intents/default_web_intent_service.cc',
+ 'browser/intents/default_web_intent_service.h',
'browser/intents/register_intent_handler_infobar_delegate.cc',
'browser/intents/register_intent_handler_infobar_delegate.h',
'browser/intents/web_intents_registry.cc',