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

Side by Side Diff: chrome/browser/extensions/activity_log/activity_log.cc

Issue 16510002: Better ActivityLog error handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup before review Created 7 years, 6 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 | 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 <set> 5 #include <set>
6 #include <vector> 6 #include <vector>
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/json/json_string_value_serializer.h" 8 #include "base/json/json_string_value_serializer.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/threading/thread_checker.h" 11 #include "base/threading/thread_checker.h"
12 #include "chrome/browser/extensions/activity_log/activity_log.h" 12 #include "chrome/browser/extensions/activity_log/activity_log.h"
13 #include "chrome/browser/extensions/activity_log/api_actions.h" 13 #include "chrome/browser/extensions/activity_log/api_actions.h"
14 #include "chrome/browser/extensions/activity_log/blocked_actions.h" 14 #include "chrome/browser/extensions/activity_log/blocked_actions.h"
15 #include "chrome/browser/extensions/api/activity_log_private/activity_log_privat e_api.h" 15 #include "chrome/browser/extensions/api/activity_log_private/activity_log_privat e_api.h"
16 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/extensions/extension_system.h" 17 #include "chrome/browser/extensions/extension_system.h"
18 #include "chrome/browser/profiles/incognito_helpers.h" 18 #include "chrome/browser/profiles/incognito_helpers.h"
19 #include "chrome/common/chrome_constants.h" 19 #include "chrome/common/chrome_constants.h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/extensions/extension.h" 21 #include "chrome/common/extensions/extension.h"
22 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
23 #include "googleurl/src/gurl.h" 23 #include "googleurl/src/gurl.h"
24 #include "sql/error_delegate_util.h"
25 #include "third_party/re2/re2/re2.h" 24 #include "third_party/re2/re2/re2.h"
26 25
27 namespace { 26 namespace {
28 27
29 // Concatenate arguments. 28 // Concatenate arguments.
30 std::string MakeArgList(const ListValue* args) { 29 std::string MakeArgList(const ListValue* args) {
31 std::string call_signature; 30 std::string call_signature;
32 ListValue::const_iterator it = args->begin(); 31 ListValue::const_iterator it = args->begin();
33 for (; it != args->end(); ++it) { 32 for (; it != args->end(); ++it) {
34 std::string arg; 33 std::string arg;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 123
125 // If the database cannot be initialized for some reason, we keep 124 // If the database cannot be initialized for some reason, we keep
126 // chugging along but nothing will get recorded. If the UI is 125 // chugging along but nothing will get recorded. If the UI is
127 // available, things will still get sent to the UI even if nothing 126 // available, things will still get sent to the UI even if nothing
128 // is being written to the database. 127 // is being written to the database.
129 db_ = new ActivityDatabase(); 128 db_ = new ActivityDatabase();
130 if (!IsLogEnabled()) return; 129 if (!IsLogEnabled()) return;
131 base::FilePath base_dir = profile->GetPath(); 130 base::FilePath base_dir = profile->GetPath();
132 base::FilePath database_name = base_dir.Append( 131 base::FilePath database_name = base_dir.Append(
133 chrome::kExtensionActivityLogFilename); 132 chrome::kExtensionActivityLogFilename);
134 db_->SetErrorCallback(base::Bind(&ActivityLog::DatabaseErrorCallback,
135 base::Unretained(this)));
136 ScheduleAndForget(&ActivityDatabase::Init, database_name); 133 ScheduleAndForget(&ActivityDatabase::Init, database_name);
137 } 134 }
138 135
139 ActivityLog::~ActivityLog() { 136 ActivityLog::~ActivityLog() {
140 ScheduleAndForget(&ActivityDatabase::Close); 137 if (dispatch_thread_ == BrowserThread::UI) // Cleanup fast in a unittest.
Matt Perry 2013/06/07 20:58:01 I think it would be better for the unit tests to f
Matt Perry 2013/06/07 20:58:01 OK, I see you're already doing RunUntilIdle. Are y
felt 2013/06/08 00:01:48 the problem is in other people's unit tests. our c
Matt Perry 2013/06/08 00:34:17 Ah, that is unfortunate. I don't have a general so
138 db_->Close();
139 else
140 ScheduleAndForget(&ActivityDatabase::Close);
141 } 141 }
142 142
143 void ActivityLog::SetArgumentLoggingForTesting(bool log_arguments) { 143 void ActivityLog::SetArgumentLoggingForTesting(bool log_arguments) {
144 testing_mode_ = log_arguments; 144 testing_mode_ = log_arguments;
145 } 145 }
146 146
147 // static 147 // static
148 ActivityLog* ActivityLog::GetInstance(Profile* profile) { 148 ActivityLog* ActivityLog::GetInstance(Profile* profile) {
149 return ActivityLogFactory::GetForProfile(profile); 149 return ActivityLogFactory::GetForProfile(profile);
150 } 150 }
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 on_url, 352 on_url,
353 web_contents->GetTitle(), 353 web_contents->GetTitle(),
354 std::string(), // no api call here 354 std::string(), // no api call here
355 script_names.get(), 355 script_names.get(),
356 DomActionType::INSERTED, 356 DomActionType::INSERTED,
357 std::string()); // no extras either 357 std::string()); // no extras either
358 } 358 }
359 } 359 }
360 } 360 }
361 361
362 void ActivityLog::DatabaseErrorCallback(int error, sql::Statement* stmt) {
363 if (sql::IsErrorCatastrophic(error))
364 ScheduleAndForget(&ActivityDatabase::KillDatabase);
365 }
366
367 } // namespace extensions 362 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698