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

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

Issue 18660004: Extension activity log database refactoring (step 1) (Closed) Base URL: http://git.chromium.org/chromium/src.git@incognito-tests
Patch Set: Change lifetime management for policies Created 7 years, 5 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 "base/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "base/json/json_string_value_serializer.h" 6 #include "base/json/json_string_value_serializer.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "chrome/browser/extensions/activity_log/activity_database.h" 9 #include "chrome/browser/extensions/activity_log/activity_database.h"
10 #include "chrome/browser/extensions/activity_log/api_actions.h" 10 #include "chrome/browser/extensions/activity_log/api_actions.h"
(...skipping 25 matching lines...) Expand all
36 36
37 namespace extensions { 37 namespace extensions {
38 38
39 // TODO(dbabic) This would be a fine error handler for all sql-based policies, 39 // TODO(dbabic) This would be a fine error handler for all sql-based policies,
40 // so it would make sense to introduce another class in the hierarchy, 40 // so it would make sense to introduce another class in the hierarchy,
41 // SQLiteBasedPolicy as a super class of FullStreamUIPolicy and move this 41 // SQLiteBasedPolicy as a super class of FullStreamUIPolicy and move this
42 // error handler (as well as other SQLite-related functionality) there. 42 // error handler (as well as other SQLite-related functionality) there.
43 43
44 FullStreamUIPolicy::FullStreamUIPolicy(Profile* profile) 44 FullStreamUIPolicy::FullStreamUIPolicy(Profile* profile)
45 : ActivityLogPolicy(profile) { 45 : ActivityLogPolicy(profile) {
46 db_ = new ActivityDatabase(); 46 db_ = new ActivityDatabase(this);
47 FilePath database_name = profile_base_path_.Append( 47 FilePath database_name = profile_base_path_.Append(
48 chrome::kExtensionActivityLogFilename); 48 chrome::kExtensionActivityLogFilename);
49 ScheduleAndForget(db_, &ActivityDatabase::Init, database_name); 49 ScheduleAndForget(db_, &ActivityDatabase::Init, database_name);
50 } 50 }
51 51
52 FullStreamUIPolicy::~FullStreamUIPolicy() { 52 bool FullStreamUIPolicy::DatabaseInitCallback(sql::Connection* db) {
53 // Create the DOMAction database.
54 if (!DOMAction::InitializeTable(db))
55 return false;
56
57 // Create the APIAction database.
58 if (!APIAction::InitializeTable(db))
59 return false;
60
61 // Create the BlockedAction database.
62 if (!BlockedAction::InitializeTable(db))
63 return false;
64
65 return true;
66 }
67
68 void FullStreamUIPolicy::DatabaseCloseCallback() {
69 delete this;
70 }
71
72 void FullStreamUIPolicy::Close() {
53 // The policy object should have never been created if there's no DB thread. 73 // The policy object should have never been created if there's no DB thread.
54 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); 74 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB));
55 ScheduleAndForget(db_, &ActivityDatabase::Close); 75 ScheduleAndForget(db_, &ActivityDatabase::Close);
56 } 76 }
57 77
58 // Get data as a set of key-value pairs. The keys are policy-specific. 78 // Get data as a set of key-value pairs. The keys are policy-specific.
59 void FullStreamUIPolicy::ReadData( 79 void FullStreamUIPolicy::ReadData(
60 const std::string& extension_id, 80 const std::string& extension_id,
61 const int day, 81 const int day,
62 const Callback 82 const Callback
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 break; 233 break;
214 } 234 }
215 default: 235 default:
216 NOTREACHED(); 236 NOTREACHED();
217 } 237 }
218 238
219 ScheduleAndForget(db_, &ActivityDatabase::RecordAction, action); 239 ScheduleAndForget(db_, &ActivityDatabase::RecordAction, action);
220 } 240 }
221 241
222 } // namespace extensions 242 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698