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

Side by Side Diff: chrome/browser/webdata/web_intents_table.cc

Issue 8144013: Add a check to the registry before the intent infobar is shown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix provider to service in comments. Created 9 years, 1 month 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/webdata/web_intents_table.h" 5 #include "chrome/browser/webdata/web_intents_table.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "googleurl/src/gurl.h" 9 #include "googleurl/src/gurl.h"
10 #include "sql/statement.h" 10 #include "sql/statement.h"
11 11
12 using webkit_glue::WebIntentServiceData; 12 using webkit_glue::WebIntentServiceData;
13 13
14 namespace { 14 namespace {
15 15
16 bool ExtractIntents(sql::Statement* s, 16 bool ExtractIntents(sql::Statement* s,
17 std::vector<WebIntentServiceData>* services) { 17 std::vector<WebIntentServiceData>* services) {
18 DCHECK(s); 18 DCHECK(s);
19 if (!s->is_valid())
20 return false;
21
19 while (s->Step()) { 22 while (s->Step()) {
20 WebIntentServiceData service; 23 WebIntentServiceData service;
21 string16 tmp = s->ColumnString16(0); 24 string16 tmp = s->ColumnString16(0);
22 service.service_url = GURL(tmp); 25 service.service_url = GURL(tmp);
23 26
24 service.action = s->ColumnString16(1); 27 service.action = s->ColumnString16(1);
25 service.type = s->ColumnString16(2); 28 service.type = s->ColumnString16(2);
26 service.title = s->ColumnString16(3); 29 service.title = s->ColumnString16(3);
27 tmp = s->ColumnString16(4); 30 tmp = s->ColumnString16(4);
28 // Default to window disposition. 31 // Default to window disposition.
(...skipping 19 matching lines...) Expand all
48 if (db_->DoesTableExist("web_intents")) 51 if (db_->DoesTableExist("web_intents"))
49 return true; 52 return true;
50 53
51 if (!db_->Execute("CREATE TABLE web_intents (" 54 if (!db_->Execute("CREATE TABLE web_intents ("
52 "service_url LONGVARCHAR," 55 "service_url LONGVARCHAR,"
53 "action VARCHAR," 56 "action VARCHAR,"
54 "type VARCHAR," 57 "type VARCHAR,"
55 "title VARCHAR," 58 "title VARCHAR,"
56 "disposition VARCHAR," 59 "disposition VARCHAR,"
57 "UNIQUE (service_url, action, type))")) { 60 "UNIQUE (service_url, action, type))")) {
58 NOTREACHED(); 61 return false;
59 } 62 }
60 63
61 if (!db_->Execute("CREATE INDEX web_intents_index ON web_intents (action)")) 64 if (!db_->Execute("CREATE INDEX web_intents_index ON web_intents (action)"))
62 NOTREACHED(); 65 return false;
63 66
64 return true; 67 return true;
65 } 68 }
66 69
67 // TODO(jhawkins): Figure out Sync story. 70 // TODO(jhawkins): Figure out Sync story.
68 bool WebIntentsTable::IsSyncable() { 71 bool WebIntentsTable::IsSyncable() {
69 return false; 72 return false;
70 } 73 }
71 74
72 bool WebIntentsTable::GetWebIntentServices( 75 bool WebIntentsTable::GetWebIntentServices(
73 const string16& action, 76 const string16& action,
74 std::vector<WebIntentServiceData>* services) { 77 std::vector<WebIntentServiceData>* services) {
75 DCHECK(services); 78 DCHECK(services);
76 sql::Statement s(db_->GetUniqueStatement( 79 sql::Statement s(db_->GetUniqueStatement(
77 "SELECT service_url, action, type, title, disposition FROM web_intents " 80 "SELECT service_url, action, type, title, disposition FROM web_intents "
78 "WHERE action=?")); 81 "WHERE action=?"));
79 if (!s)
80 NOTREACHED() << "Statement prepare failed";
81 82
82 s.BindString16(0, action); 83 s.BindString16(0, action);
83 return ExtractIntents(&s, services); 84 return ExtractIntents(&s, services);
84 } 85 }
85 86
87 // TODO(gbillock): This currently does a full-table scan. Eventually we will
88 // store registrations by domain, and so have an indexed origin. At that time,
89 // this should just change to do lookup by origin instead of URL.
90 bool WebIntentsTable::GetWebIntentServicesForURL(
91 const string16& service_url,
92 std::vector<WebIntentServiceData>* services) {
93 DCHECK(services);
94 sql::Statement s(db_->GetUniqueStatement(
95 "SELECT service_url, action, type, title, disposition FROM web_intents "
96 "WHERE service_url=?"));
97
98 s.BindString16(0, service_url);
99 return ExtractIntents(&s, services);
100 }
101
86 bool WebIntentsTable::GetAllWebIntentServices( 102 bool WebIntentsTable::GetAllWebIntentServices(
87 std::vector<WebIntentServiceData>* services) { 103 std::vector<WebIntentServiceData>* services) {
88 DCHECK(services); 104 DCHECK(services);
89 sql::Statement s(db_->GetUniqueStatement( 105 sql::Statement s(db_->GetUniqueStatement(
90 "SELECT service_url, action, type, title, disposition FROM web_intents")); 106 "SELECT service_url, action, type, title, disposition FROM web_intents"));
91 if (!s)
92 NOTREACHED() << "Statement prepare failed";
93 107
94 return ExtractIntents(&s, services); 108 return ExtractIntents(&s, services);
95 } 109 }
96 110
97 bool WebIntentsTable::SetWebIntentService(const WebIntentServiceData& service) { 111 bool WebIntentsTable::SetWebIntentService(const WebIntentServiceData& service) {
98 sql::Statement s(db_->GetUniqueStatement( 112 sql::Statement s(db_->GetUniqueStatement(
99 "INSERT OR REPLACE INTO web_intents " 113 "INSERT OR REPLACE INTO web_intents "
100 "(service_url, type, action, title, disposition) " 114 "(service_url, type, action, title, disposition) "
101 "VALUES (?, ?, ?, ?, ?)")); 115 "VALUES (?, ?, ?, ?, ?)"));
102 if (!s)
103 NOTREACHED() << "Statement prepare failed";
104 116
105 // Default to window disposition. 117 // Default to window disposition.
106 string16 disposition = ASCIIToUTF16("window"); 118 string16 disposition = ASCIIToUTF16("window");
107 if (service.disposition == WebIntentServiceData::DISPOSITION_INLINE) 119 if (service.disposition == WebIntentServiceData::DISPOSITION_INLINE)
108 disposition = ASCIIToUTF16("inline"); 120 disposition = ASCIIToUTF16("inline");
109 s.BindString(0, service.service_url.spec()); 121 s.BindString(0, service.service_url.spec());
110 s.BindString16(1, service.type); 122 s.BindString16(1, service.type);
111 s.BindString16(2, service.action); 123 s.BindString16(2, service.action);
112 s.BindString16(3, service.title); 124 s.BindString16(3, service.title);
113 s.BindString16(4, disposition); 125 s.BindString16(4, disposition);
114 return s.Run(); 126 return s.Run();
115 } 127 }
116 128
117 // TODO(jhawkins): Investigate the need to remove rows matching only 129 // TODO(jhawkins): Investigate the need to remove rows matching only
118 // |service.service_url|. It's unlikely the user will be given the ability to 130 // |service.service_url|. It's unlikely the user will be given the ability to
119 // remove at the granularity of actions or types. 131 // remove at the granularity of actions or types.
120 bool WebIntentsTable::RemoveWebIntentService( 132 bool WebIntentsTable::RemoveWebIntentService(
121 const WebIntentServiceData& service) { 133 const WebIntentServiceData& service) {
122 sql::Statement s(db_->GetUniqueStatement( 134 sql::Statement s(db_->GetUniqueStatement(
123 "DELETE FROM web_intents " 135 "DELETE FROM web_intents "
124 "WHERE service_url = ? AND action = ? AND type = ?")); 136 "WHERE service_url = ? AND action = ? AND type = ?"));
125 if (!s)
126 NOTREACHED() << "Statement prepare failed";
127 137
128 s.BindString(0, service.service_url.spec()); 138 s.BindString(0, service.service_url.spec());
129 s.BindString16(1, service.action); 139 s.BindString16(1, service.action);
130 s.BindString16(2, service.type); 140 s.BindString16(2, service.type);
131 return s.Run(); 141 return s.Run();
132 } 142 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_intents_table.h ('k') | chrome/browser/webdata/web_intents_table_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698