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

Side by Side Diff: content/child/web_database_observer_impl.cc

Issue 1779413002: Remove Blink's DatabaseIdentifier implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unneeded include Created 4 years, 9 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/child/web_database_observer_impl.h" 5 #include "content/child/web_database_observer_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "content/child/storage_util.h"
12 #include "content/common/database_messages.h" 13 #include "content/common/database_messages.h"
14 #include "storage/common/database/database_identifier.h"
15 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
13 #include "third_party/WebKit/public/platform/WebString.h" 16 #include "third_party/WebKit/public/platform/WebString.h"
14 #include "third_party/sqlite/sqlite3.h" 17 #include "third_party/sqlite/sqlite3.h"
15 18
19 using blink::WebSecurityOrigin;
16 using blink::WebString; 20 using blink::WebString;
17 21
18 namespace content { 22 namespace content {
19 23
20 namespace { 24 namespace {
21 25
22 const int kResultHistogramSize = 50; 26 const int kResultHistogramSize = 50;
23 const int kCallsiteHistogramSize = 10; 27 const int kCallsiteHistogramSize = 10;
24 const int kWebSQLSuccess = -1; 28 const int kWebSQLSuccess = -1;
25 29
(...skipping 19 matching lines...) Expand all
45 do { \ 49 do { \
46 DCHECK(callsite < kCallsiteHistogramSize); \ 50 DCHECK(callsite < kCallsiteHistogramSize); \
47 int result = DetermineHistogramResult(websql_error, sqlite_error); \ 51 int result = DetermineHistogramResult(websql_error, sqlite_error); \
48 UMA_HISTOGRAM_ENUMERATION("websql.Async." name, \ 52 UMA_HISTOGRAM_ENUMERATION("websql.Async." name, \
49 result, kResultHistogramSize); \ 53 result, kResultHistogramSize); \
50 if (result) { \ 54 if (result) { \
51 UMA_HISTOGRAM_ENUMERATION("websql.Async." name ".ErrorSite", \ 55 UMA_HISTOGRAM_ENUMERATION("websql.Async." name ".ErrorSite", \
52 callsite, kCallsiteHistogramSize); \ 56 callsite, kCallsiteHistogramSize); \
53 } \ 57 } \
54 } while (0) 58 } while (0)
59
60 // TODO(jsbell): Replace with use of url::Origin end-to-end.
61 // https://crbug.com/591482
62 std::string GetIdentifierFromOrigin(const WebSecurityOrigin& origin) {
63 return storage::GetIdentifierFromOrigin(WebSecurityOriginToGURL(origin));
64 }
65
55 } // namespace 66 } // namespace
56 67
57 WebDatabaseObserverImpl::WebDatabaseObserverImpl(IPC::SyncMessageFilter* sender) 68 WebDatabaseObserverImpl::WebDatabaseObserverImpl(IPC::SyncMessageFilter* sender)
58 : sender_(sender), 69 : sender_(sender),
59 open_connections_(new storage::DatabaseConnectionsWrapper), 70 open_connections_(new storage::DatabaseConnectionsWrapper),
60 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) { 71 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) {
61 DCHECK(sender); 72 DCHECK(sender);
62 DCHECK(main_thread_task_runner_); 73 DCHECK(main_thread_task_runner_);
63 } 74 }
64 75
65 WebDatabaseObserverImpl::~WebDatabaseObserverImpl() { 76 WebDatabaseObserverImpl::~WebDatabaseObserverImpl() {
66 } 77 }
67 78
68 void WebDatabaseObserverImpl::databaseOpened( 79 void WebDatabaseObserverImpl::databaseOpened(
69 const WebString& origin_identifier, 80 const WebSecurityOrigin& origin,
70 const WebString& database_name, 81 const WebString& database_name,
71 const WebString& database_display_name, 82 const WebString& database_display_name,
72 unsigned long estimated_size) { 83 unsigned long estimated_size) {
73 open_connections_->AddOpenConnection(origin_identifier.utf8(), 84 const std::string origin_identifier = GetIdentifierFromOrigin(origin);
74 database_name); 85 open_connections_->AddOpenConnection(origin_identifier, database_name);
75 sender_->Send(new DatabaseHostMsg_Opened( 86 sender_->Send(new DatabaseHostMsg_Opened(
76 origin_identifier.utf8(), database_name, 87 origin_identifier, database_name, database_display_name, estimated_size));
77 database_display_name, estimated_size));
78 } 88 }
79 89
80 void WebDatabaseObserverImpl::databaseModified( 90 void WebDatabaseObserverImpl::databaseModified(const WebSecurityOrigin& origin,
81 const WebString& origin_identifier, 91 const WebString& database_name) {
82 const WebString& database_name) { 92 sender_->Send(new DatabaseHostMsg_Modified(GetIdentifierFromOrigin(origin),
83 sender_->Send(new DatabaseHostMsg_Modified( 93 database_name));
84 origin_identifier.utf8(), database_name));
85 } 94 }
86 95
87 void WebDatabaseObserverImpl::databaseClosed( 96 void WebDatabaseObserverImpl::databaseClosed(const WebSecurityOrigin& origin,
88 const WebString& origin_identifier, 97 const WebString& database_name) {
89 const WebString& database_name) {
90 DCHECK(!main_thread_task_runner_->RunsTasksOnCurrentThread()); 98 DCHECK(!main_thread_task_runner_->RunsTasksOnCurrentThread());
99 const std::string origin_identifier = GetIdentifierFromOrigin(origin);
91 main_thread_task_runner_->PostTask( 100 main_thread_task_runner_->PostTask(
92 FROM_HERE, 101 FROM_HERE,
93 base::Bind( 102 base::Bind(base::IgnoreResult(&IPC::SyncMessageFilter::Send), sender_,
94 base::IgnoreResult(&IPC::SyncMessageFilter::Send), 103 new DatabaseHostMsg_Closed(origin_identifier, database_name)));
95 sender_, 104 open_connections_->RemoveOpenConnection(origin_identifier, database_name);
96 new DatabaseHostMsg_Closed(origin_identifier.utf8(), database_name)));
97 open_connections_->RemoveOpenConnection(origin_identifier.utf8(),
98 database_name);
99 } 105 }
100 106
101 void WebDatabaseObserverImpl::reportOpenDatabaseResult( 107 void WebDatabaseObserverImpl::reportOpenDatabaseResult(
102 const WebString& origin_identifier, 108 const WebSecurityOrigin& origin,
103 const WebString& database_name, 109 const WebString& database_name,
104 int callsite, 110 int callsite,
105 int websql_error, 111 int websql_error,
106 int sqlite_error, 112 int sqlite_error,
107 double call_time) { 113 double call_time) {
108 UMA_HISTOGRAM_WEBSQL_RESULT("OpenResult", callsite, 114 UMA_HISTOGRAM_WEBSQL_RESULT("OpenResult", callsite,
109 websql_error, sqlite_error); 115 websql_error, sqlite_error);
110 HandleSqliteError(origin_identifier, database_name, sqlite_error); 116 HandleSqliteError(origin, database_name, sqlite_error);
111 117
112 if (websql_error == kWebSQLSuccess && sqlite_error == SQLITE_OK) { 118 if (websql_error == kWebSQLSuccess && sqlite_error == SQLITE_OK) {
113 UMA_HISTOGRAM_TIMES("websql.Async.OpenTime.Success", 119 UMA_HISTOGRAM_TIMES("websql.Async.OpenTime.Success",
114 base::TimeDelta::FromSecondsD(call_time)); 120 base::TimeDelta::FromSecondsD(call_time));
115 } else { 121 } else {
116 UMA_HISTOGRAM_TIMES("websql.Async.OpenTime.Error", 122 UMA_HISTOGRAM_TIMES("websql.Async.OpenTime.Error",
117 base::TimeDelta::FromSecondsD(call_time)); 123 base::TimeDelta::FromSecondsD(call_time));
118 } 124 }
119 } 125 }
120 126
121 void WebDatabaseObserverImpl::reportChangeVersionResult( 127 void WebDatabaseObserverImpl::reportChangeVersionResult(
122 const WebString& origin_identifier, 128 const WebSecurityOrigin& origin,
123 const WebString& database_name, 129 const WebString& database_name,
124 int callsite, int websql_error, int sqlite_error) { 130 int callsite,
131 int websql_error,
132 int sqlite_error) {
125 UMA_HISTOGRAM_WEBSQL_RESULT("ChangeVersionResult", callsite, 133 UMA_HISTOGRAM_WEBSQL_RESULT("ChangeVersionResult", callsite,
126 websql_error, sqlite_error); 134 websql_error, sqlite_error);
127 HandleSqliteError(origin_identifier, database_name, sqlite_error); 135 HandleSqliteError(origin, database_name, sqlite_error);
128 } 136 }
129 137
130 void WebDatabaseObserverImpl::reportStartTransactionResult( 138 void WebDatabaseObserverImpl::reportStartTransactionResult(
131 const WebString& origin_identifier, 139 const WebSecurityOrigin& origin,
132 const WebString& database_name, 140 const WebString& database_name,
133 int callsite, int websql_error, int sqlite_error) { 141 int callsite,
142 int websql_error,
143 int sqlite_error) {
134 UMA_HISTOGRAM_WEBSQL_RESULT("BeginResult", callsite, 144 UMA_HISTOGRAM_WEBSQL_RESULT("BeginResult", callsite,
135 websql_error, sqlite_error); 145 websql_error, sqlite_error);
136 HandleSqliteError(origin_identifier, database_name, sqlite_error); 146 HandleSqliteError(origin, database_name, sqlite_error);
137 } 147 }
138 148
139 void WebDatabaseObserverImpl::reportCommitTransactionResult( 149 void WebDatabaseObserverImpl::reportCommitTransactionResult(
140 const WebString& origin_identifier, 150 const WebSecurityOrigin& origin,
141 const WebString& database_name, 151 const WebString& database_name,
142 int callsite, int websql_error, int sqlite_error) { 152 int callsite,
153 int websql_error,
154 int sqlite_error) {
143 UMA_HISTOGRAM_WEBSQL_RESULT("CommitResult", callsite, 155 UMA_HISTOGRAM_WEBSQL_RESULT("CommitResult", callsite,
144 websql_error, sqlite_error); 156 websql_error, sqlite_error);
145 HandleSqliteError(origin_identifier, database_name, sqlite_error); 157 HandleSqliteError(origin, database_name, sqlite_error);
146 } 158 }
147 159
148 void WebDatabaseObserverImpl::reportExecuteStatementResult( 160 void WebDatabaseObserverImpl::reportExecuteStatementResult(
149 const WebString& origin_identifier, 161 const WebSecurityOrigin& origin,
150 const WebString& database_name, 162 const WebString& database_name,
151 int callsite, int websql_error, int sqlite_error) { 163 int callsite,
164 int websql_error,
165 int sqlite_error) {
152 UMA_HISTOGRAM_WEBSQL_RESULT("StatementResult", callsite, 166 UMA_HISTOGRAM_WEBSQL_RESULT("StatementResult", callsite,
153 websql_error, sqlite_error); 167 websql_error, sqlite_error);
154 HandleSqliteError(origin_identifier, database_name, sqlite_error); 168 HandleSqliteError(origin, database_name, sqlite_error);
155 } 169 }
156 170
157 void WebDatabaseObserverImpl::reportVacuumDatabaseResult( 171 void WebDatabaseObserverImpl::reportVacuumDatabaseResult(
158 const WebString& origin_identifier, 172 const WebSecurityOrigin& origin,
159 const WebString& database_name, 173 const WebString& database_name,
160 int sqlite_error) { 174 int sqlite_error) {
161 int result = DetermineHistogramResult(-1, sqlite_error); 175 int result = DetermineHistogramResult(-1, sqlite_error);
162 UMA_HISTOGRAM_ENUMERATION("websql.Async.VacuumResult", 176 UMA_HISTOGRAM_ENUMERATION("websql.Async.VacuumResult",
163 result, kResultHistogramSize); 177 result, kResultHistogramSize);
164 178 HandleSqliteError(origin, database_name, sqlite_error);
165 HandleSqliteError(origin_identifier, database_name, sqlite_error);
166 } 179 }
167 180
168 bool WebDatabaseObserverImpl::WaitForAllDatabasesToClose( 181 bool WebDatabaseObserverImpl::WaitForAllDatabasesToClose(
169 base::TimeDelta timeout) { 182 base::TimeDelta timeout) {
170 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); 183 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread());
171 return open_connections_->WaitForAllDatabasesToClose(timeout); 184 return open_connections_->WaitForAllDatabasesToClose(timeout);
172 } 185 }
173 186
174 void WebDatabaseObserverImpl::HandleSqliteError( 187 void WebDatabaseObserverImpl::HandleSqliteError(const WebSecurityOrigin& origin,
175 const WebString& origin_identifier, 188 const WebString& database_name,
176 const WebString& database_name, 189 int error) {
177 int error) {
178 // We filter out errors which the backend doesn't act on to avoid 190 // We filter out errors which the backend doesn't act on to avoid
179 // a unnecessary ipc traffic, this method can get called at a fairly 191 // a unnecessary ipc traffic, this method can get called at a fairly
180 // high frequency (per-sqlstatement). 192 // high frequency (per-sqlstatement).
181 if (error == SQLITE_CORRUPT || error == SQLITE_NOTADB) { 193 if (error == SQLITE_CORRUPT || error == SQLITE_NOTADB) {
182 sender_->Send(new DatabaseHostMsg_HandleSqliteError( 194 sender_->Send(new DatabaseHostMsg_HandleSqliteError(
183 origin_identifier.utf8(), 195 GetIdentifierFromOrigin(origin), database_name, error));
184 database_name,
185 error));
186 } 196 }
187 } 197 }
188 198
189 } // namespace content 199 } // namespace content
OLDNEW
« no previous file with comments | « content/child/web_database_observer_impl.h ('k') | content/renderer/renderer_blink_platform_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698