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

Side by Side Diff: chrome/browser/net/sqlite_persistent_cookie_store.cc

Issue 6201005: Initial support for partitioning cookies for isolated apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix automation_util and thread issue. Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/net/sqlite_persistent_cookie_store.h" 5 #include "chrome/browser/net/sqlite_persistent_cookie_store.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "app/sql/meta_table.h" 9 #include "app/sql/meta_table.h"
10 #include "app/sql/statement.h" 10 #include "app/sql/statement.h"
11 #include "app/sql/transaction.h" 11 #include "app/sql/transaction.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/ref_counted.h" 17 #include "base/ref_counted.h"
18 #include "base/scoped_ptr.h" 18 #include "base/scoped_ptr.h"
19 #include "base/string_util.h" 19 #include "base/string_util.h"
20 #include "base/threading/thread.h" 20 #include "base/threading/thread.h"
21 #include "base/threading/thread_restrictions.h"
21 #include "chrome/browser/diagnostics/sqlite_diagnostics.h" 22 #include "chrome/browser/diagnostics/sqlite_diagnostics.h"
22 #include "content/browser/browser_thread.h" 23 #include "content/browser/browser_thread.h"
23 #include "googleurl/src/gurl.h" 24 #include "googleurl/src/gurl.h"
24 25
25 using base::Time; 26 using base::Time;
26 27
27 // This class is designed to be shared between any calling threads and the 28 // This class is designed to be shared between any calling threads and the
28 // database thread. It batches operations and commits them on a timer. 29 // database thread. It batches operations and commits them on a timer.
29 class SQLitePersistentCookieStore::Backend 30 class SQLitePersistentCookieStore::Backend
30 : public base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend> { 31 : public base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend> {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 return true; 150 return true;
150 } 151 }
151 152
152 } // namespace 153 } // namespace
153 154
154 bool SQLitePersistentCookieStore::Backend::Load( 155 bool SQLitePersistentCookieStore::Backend::Load(
155 std::vector<net::CookieMonster::CanonicalCookie*>* cookies) { 156 std::vector<net::CookieMonster::CanonicalCookie*>* cookies) {
156 // This function should be called only once per instance. 157 // This function should be called only once per instance.
157 DCHECK(!db_.get()); 158 DCHECK(!db_.get());
158 159
160 // Ensure the parent directory for storing cookies is created before reading
161 // from it. We make an exception to allow IO on the UI thread here because
162 // we are going to disk anyway in db_->Open. (This code will be moved to the
163 // DB thread as part of http://crbug.com/52909.)
164 base::ThreadRestrictions::ScopedAllowIO allow_io;
Matt Perry 2011/03/08 21:27:56 put this new code in an indented scope to limit th
Charlie Reis 2011/03/08 22:26:58 Done.
165 const FilePath dir = path_.DirName();
166 if (!file_util::PathExists(dir) && !file_util::CreateDirectory(dir))
167 return false;
168
159 db_.reset(new sql::Connection); 169 db_.reset(new sql::Connection);
160 if (!db_->Open(path_)) { 170 if (!db_->Open(path_)) {
161 NOTREACHED() << "Unable to open cookie DB."; 171 NOTREACHED() << "Unable to open cookie DB.";
162 db_.reset(); 172 db_.reset();
163 return false; 173 return false;
164 } 174 }
165 175
166 db_->set_error_delegate(GetErrorHandlerForCookieDb()); 176 db_->set_error_delegate(GetErrorHandlerForCookieDb());
167 177
168 if (!EnsureDatabaseVersion() || !InitTable(db_.get())) { 178 if (!EnsureDatabaseVersion() || !InitTable(db_.get())) {
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 if (backend_.get()) 506 if (backend_.get())
497 backend_->SetClearLocalStateOnExit(clear_local_state); 507 backend_->SetClearLocalStateOnExit(clear_local_state);
498 } 508 }
499 509
500 void SQLitePersistentCookieStore::Flush(Task* completion_task) { 510 void SQLitePersistentCookieStore::Flush(Task* completion_task) {
501 if (backend_.get()) 511 if (backend_.get())
502 backend_->Flush(completion_task); 512 backend_->Flush(completion_task);
503 else if (completion_task) 513 else if (completion_task)
504 MessageLoop::current()->PostTask(FROM_HERE, completion_task); 514 MessageLoop::current()->PostTask(FROM_HERE, completion_task);
505 } 515 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698