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

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

Issue 8417043: Add webkit_glue namespace. Improve some variable and test names. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge error 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;
13
12 namespace { 14 namespace {
15
13 bool ExtractIntents(sql::Statement* s, 16 bool ExtractIntents(sql::Statement* s,
14 std::vector<WebIntentServiceData>* services) { 17 std::vector<WebIntentServiceData>* services) {
15 DCHECK(s); 18 DCHECK(s);
16 while (s->Step()) { 19 while (s->Step()) {
17 WebIntentServiceData service; 20 WebIntentServiceData service;
18 string16 tmp = s->ColumnString16(0); 21 string16 tmp = s->ColumnString16(0);
19 service.service_url = GURL(tmp); 22 service.service_url = GURL(tmp);
20 23
21 service.action = s->ColumnString16(1); 24 service.action = s->ColumnString16(1);
22 service.type = s->ColumnString16(2); 25 service.type = s->ColumnString16(2);
23 service.title = s->ColumnString16(3); 26 service.title = s->ColumnString16(3);
24 tmp = s->ColumnString16(4); 27 tmp = s->ColumnString16(4);
25 // Default to window disposition. 28 // Default to window disposition.
26 service.disposition = WebIntentServiceData::DISPOSITION_WINDOW; 29 service.disposition = WebIntentServiceData::DISPOSITION_WINDOW;
27 if (tmp == ASCIIToUTF16("inline")) 30 if (tmp == ASCIIToUTF16("inline"))
28 service.disposition = WebIntentServiceData::DISPOSITION_INLINE; 31 service.disposition = WebIntentServiceData::DISPOSITION_INLINE;
29 services->push_back(service); 32 services->push_back(service);
30 } 33 }
31 return true; 34 return true;
32 } 35 }
33 } 36
37 } // namespace
34 38
35 WebIntentsTable::WebIntentsTable(sql::Connection* db, 39 WebIntentsTable::WebIntentsTable(sql::Connection* db,
36 sql::MetaTable* meta_table) 40 sql::MetaTable* meta_table)
37 : WebDatabaseTable(db, meta_table) { 41 : WebDatabaseTable(db, meta_table) {
38 } 42 }
39 43
40 WebIntentsTable::~WebIntentsTable() { 44 WebIntentsTable::~WebIntentsTable() {
41 } 45 }
42 46
43 bool WebIntentsTable::Init() { 47 bool WebIntentsTable::Init() {
(...skipping 16 matching lines...) Expand all
60 return true; 64 return true;
61 } 65 }
62 66
63 // TODO(jhawkins): Figure out Sync story. 67 // TODO(jhawkins): Figure out Sync story.
64 bool WebIntentsTable::IsSyncable() { 68 bool WebIntentsTable::IsSyncable() {
65 return false; 69 return false;
66 } 70 }
67 71
68 bool WebIntentsTable::GetWebIntents( 72 bool WebIntentsTable::GetWebIntents(
69 const string16& action, 73 const string16& action,
70 std::vector<WebIntentServiceData>* intents) { 74 std::vector<WebIntentServiceData>* services) {
71 DCHECK(intents); 75 DCHECK(services);
72 sql::Statement s(db_->GetUniqueStatement( 76 sql::Statement s(db_->GetUniqueStatement(
73 "SELECT service_url, action, type, title, disposition FROM web_intents " 77 "SELECT service_url, action, type, title, disposition FROM web_intents "
74 "WHERE action=?")); 78 "WHERE action=?"));
75 if (!s) 79 if (!s)
76 NOTREACHED() << "Statement prepare failed"; 80 NOTREACHED() << "Statement prepare failed";
77 81
78 s.BindString16(0, action); 82 s.BindString16(0, action);
79 return ExtractIntents(&s, intents); 83 return ExtractIntents(&s, services);
80 } 84 }
81 85
82 bool WebIntentsTable::GetAllWebIntents( 86 bool WebIntentsTable::GetAllWebIntents(
83 std::vector<WebIntentServiceData>* intents) { 87 std::vector<WebIntentServiceData>* services) {
84 DCHECK(intents); 88 DCHECK(services);
85 sql::Statement s(db_->GetUniqueStatement( 89 sql::Statement s(db_->GetUniqueStatement(
86 "SELECT service_url, action, type, title, disposition FROM web_intents")); 90 "SELECT service_url, action, type, title, disposition FROM web_intents"));
87 if (!s) 91 if (!s)
88 NOTREACHED() << "Statement prepare failed"; 92 NOTREACHED() << "Statement prepare failed";
89 93
90 return ExtractIntents(&s, intents); 94 return ExtractIntents(&s, services);
91 } 95 }
92 96
93 bool WebIntentsTable::SetWebIntent(const WebIntentServiceData& intent) { 97 bool WebIntentsTable::SetWebIntent(const WebIntentServiceData& service) {
94 sql::Statement s(db_->GetUniqueStatement( 98 sql::Statement s(db_->GetUniqueStatement(
95 "INSERT OR REPLACE INTO web_intents " 99 "INSERT OR REPLACE INTO web_intents "
96 "(service_url, type, action, title, disposition) " 100 "(service_url, type, action, title, disposition) "
97 "VALUES (?, ?, ?, ?, ?)")); 101 "VALUES (?, ?, ?, ?, ?)"));
98 if (!s) 102 if (!s)
99 NOTREACHED() << "Statement prepare failed"; 103 NOTREACHED() << "Statement prepare failed";
100 104
101 // Default to window disposition. 105 // Default to window disposition.
102 string16 disposition = ASCIIToUTF16("window"); 106 string16 disposition = ASCIIToUTF16("window");
103 if (intent.disposition == WebIntentServiceData::DISPOSITION_INLINE) 107 if (service.disposition == WebIntentServiceData::DISPOSITION_INLINE)
104 disposition = ASCIIToUTF16("inline"); 108 disposition = ASCIIToUTF16("inline");
105 s.BindString(0, intent.service_url.spec()); 109 s.BindString(0, service.service_url.spec());
106 s.BindString16(1, intent.type); 110 s.BindString16(1, service.type);
107 s.BindString16(2, intent.action); 111 s.BindString16(2, service.action);
108 s.BindString16(3, intent.title); 112 s.BindString16(3, service.title);
109 s.BindString16(4, disposition); 113 s.BindString16(4, disposition);
110 return s.Run(); 114 return s.Run();
111 } 115 }
112 116
113 // TODO(jhawkins): Investigate the need to remove rows matching only 117 // TODO(jhawkins): Investigate the need to remove rows matching only
114 // |intent.service_url|. It's unlikely the user will be given the ability to 118 // |service.service_url|. It's unlikely the user will be given the ability to
115 // remove at the granularity of actions or types. 119 // remove at the granularity of actions or types.
116 bool WebIntentsTable::RemoveWebIntent(const WebIntentServiceData& intent) { 120 bool WebIntentsTable::RemoveWebIntent(const WebIntentServiceData& service) {
117 sql::Statement s(db_->GetUniqueStatement( 121 sql::Statement s(db_->GetUniqueStatement(
118 "DELETE FROM web_intents " 122 "DELETE FROM web_intents "
119 "WHERE service_url = ? AND action = ? AND type = ?")); 123 "WHERE service_url = ? AND action = ? AND type = ?"));
120 if (!s) 124 if (!s)
121 NOTREACHED() << "Statement prepare failed"; 125 NOTREACHED() << "Statement prepare failed";
122 126
123 s.BindString(0, intent.service_url.spec()); 127 s.BindString(0, service.service_url.spec());
124 s.BindString16(1, intent.action); 128 s.BindString16(1, service.action);
125 s.BindString16(2, intent.type); 129 s.BindString16(2, service.type);
126 return s.Run(); 130 return s.Run();
127 } 131 }
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