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

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

Issue 16756004: Revert 205059 "We were seeing ActivityLog memory leaks and assor..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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/extensions/extension_system_factory.h" 18 #include "chrome/browser/extensions/extension_system_factory.h"
19 #include "chrome/browser/extensions/install_tracker_factory.h" 19 #include "chrome/browser/extensions/install_tracker_factory.h"
20 #include "chrome/browser/prerender/prerender_manager.h" 20 #include "chrome/browser/prerender/prerender_manager.h"
21 #include "chrome/browser/prerender/prerender_manager_factory.h" 21 #include "chrome/browser/prerender/prerender_manager_factory.h"
22 #include "chrome/browser/profiles/incognito_helpers.h" 22 #include "chrome/browser/profiles/incognito_helpers.h"
23 #include "chrome/common/chrome_constants.h" 23 #include "chrome/common/chrome_constants.h"
24 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/extensions/extension.h" 25 #include "chrome/common/extensions/extension.h"
26 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" 26 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h"
27 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
28 #include "googleurl/src/gurl.h" 28 #include "googleurl/src/gurl.h"
29 #include "sql/error_delegate_util.h"
29 #include "third_party/re2/re2/re2.h" 30 #include "third_party/re2/re2/re2.h"
30 31
31 namespace { 32 namespace {
32 33
33 // Concatenate arguments. 34 // Concatenate arguments.
34 std::string MakeArgList(const ListValue* args) { 35 std::string MakeArgList(const ListValue* args) {
35 std::string call_signature; 36 std::string call_signature;
36 ListValue::const_iterator it = args->begin(); 37 ListValue::const_iterator it = args->begin();
37 for (; it != args->end(); ++it) { 38 for (; it != args->end(); ++it) {
38 std::string arg; 39 std::string arg;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 // We initialize the database whether or not the AL is enabled, since we might 162 // We initialize the database whether or not the AL is enabled, since we might
162 // be enabled later on. If the database cannot be initialized for some 163 // be enabled later on. If the database cannot be initialized for some
163 // reason, we keep chugging along but nothing will get recorded. If the UI is 164 // reason, we keep chugging along but nothing will get recorded. If the UI is
164 // available, things will still get sent to the UI even if nothing 165 // available, things will still get sent to the UI even if nothing
165 // is being written to the database. 166 // is being written to the database.
166 db_ = new ActivityDatabase(); 167 db_ = new ActivityDatabase();
167 if (!has_threads_) return; 168 if (!has_threads_) return;
168 base::FilePath base_dir = profile->GetPath(); 169 base::FilePath base_dir = profile->GetPath();
169 base::FilePath database_name = base_dir.Append( 170 base::FilePath database_name = base_dir.Append(
170 chrome::kExtensionActivityLogFilename); 171 chrome::kExtensionActivityLogFilename);
172 db_->SetErrorCallback(base::Bind(&ActivityLog::DatabaseErrorCallback,
173 base::Unretained(this)));
171 ScheduleAndForget(&ActivityDatabase::Init, database_name); 174 ScheduleAndForget(&ActivityDatabase::Init, database_name);
172 } 175 }
173 176
174 void ActivityLog::Shutdown() { 177 void ActivityLog::Shutdown() {
175 if (!first_time_checking_ && tracker_) tracker_->RemoveObserver(this); 178 if (!first_time_checking_ && tracker_) tracker_->RemoveObserver(this);
176 } 179 }
177 180
178 ActivityLog::~ActivityLog() { 181 ActivityLog::~ActivityLog() {
179 if (has_threads_) 182 ScheduleAndForget(&ActivityDatabase::Close);
180 ScheduleAndForget(&ActivityDatabase::Close);
181 else
182 db_->Close();
183 } 183 }
184 184
185 // We can't register for the InstallTrackerFactory events or talk to the 185 // We can't register for the InstallTrackerFactory events or talk to the
186 // extension service in the constructor, so we do that here the first time 186 // extension service in the constructor, so we do that here the first time
187 // this is called (as identified by first_time_checking_). 187 // this is called (as identified by first_time_checking_).
188 bool ActivityLog::IsLogEnabled() { 188 bool ActivityLog::IsLogEnabled() {
189 if (!first_time_checking_) return enabled_; 189 if (!first_time_checking_) return enabled_;
190 if (!has_threads_) return false; 190 if (!has_threads_) return false;
191 tracker_ = InstallTrackerFactory::GetForProfile(profile_); 191 tracker_ = InstallTrackerFactory::GetForProfile(profile_);
192 tracker_->AddObserver(this); 192 tracker_->AddObserver(this);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 on_url, 444 on_url,
445 web_contents->GetTitle(), 445 web_contents->GetTitle(),
446 std::string(), // no api call here 446 std::string(), // no api call here
447 script_names.get(), 447 script_names.get(),
448 DomActionType::INSERTED, 448 DomActionType::INSERTED,
449 extra); 449 extra);
450 } 450 }
451 } 451 }
452 } 452 }
453 453
454 void ActivityLog::DatabaseErrorCallback(int error, sql::Statement* stmt) {
455 if (sql::IsErrorCatastrophic(error))
456 ScheduleAndForget(&ActivityDatabase::KillDatabase);
457 }
458
454 } // namespace extensions 459 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698