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

Side by Side Diff: chrome/browser/in_process_webkit/indexed_db_context.cc

Issue 5359005: Moved deleting the indexed db context to the WebKitContext destructor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up static modifer from the ClearLocalState method. Created 10 years 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/in_process_webkit/indexed_db_context.h" 5 #include "chrome/browser/in_process_webkit/indexed_db_context.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/browser_thread.h" 11 #include "chrome/browser/browser_thread.h"
12 #include "chrome/browser/in_process_webkit/webkit_context.h" 12 #include "chrome/browser/in_process_webkit/webkit_context.h"
13 #include "chrome/common/url_constants.h"
13 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" 14 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
14 #include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabase.h" 15 #include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabase.h"
15 #include "third_party/WebKit/WebKit/chromium/public/WebIDBFactory.h" 16 #include "third_party/WebKit/WebKit/chromium/public/WebIDBFactory.h"
16 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" 17 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
17 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" 18 #include "third_party/WebKit/WebKit/chromium/public/WebString.h"
18 #include "webkit/glue/webkit_glue.h" 19 #include "webkit/glue/webkit_glue.h"
19 20
20 using WebKit::WebIDBDatabase; 21 using WebKit::WebIDBDatabase;
21 using WebKit::WebIDBFactory; 22 using WebKit::WebIDBFactory;
22 using WebKit::WebSecurityOrigin; 23 using WebKit::WebSecurityOrigin;
23 24
24 const FilePath::CharType IndexedDBContext::kIndexedDBDirectory[] = 25 const FilePath::CharType IndexedDBContext::kIndexedDBDirectory[] =
25 FILE_PATH_LITERAL("IndexedDB"); 26 FILE_PATH_LITERAL("IndexedDB");
26 27
27 const FilePath::CharType IndexedDBContext::kIndexedDBExtension[] = 28 const FilePath::CharType IndexedDBContext::kIndexedDBExtension[] =
28 FILE_PATH_LITERAL(".indexeddb"); 29 FILE_PATH_LITERAL(".indexeddb");
29 30
30 IndexedDBContext::IndexedDBContext(WebKitContext* webkit_context) 31 IndexedDBContext::IndexedDBContext(WebKitContext* webkit_context) {
31 : webkit_context_(webkit_context) { 32 data_path_ = webkit_context->data_path().Append(kIndexedDBDirectory);
32 } 33 }
33 34
34 IndexedDBContext::~IndexedDBContext() { 35 IndexedDBContext::~IndexedDBContext() {
36 // Not being on the WEBKIT thread here means we are running in a unit test
37 // where no clean up is needed.
38 if (clear_local_state_on_exit_ &&
39 BrowserThread::CurrentlyOn(BrowserThread::WEBKIT))
40 ClearLocalState(data_path_, chrome::kExtensionScheme);
jochen (gone - plz use gerrit) 2010/11/29 10:45:24 indent only two spaces. also, ClearLocalState does
pastarmovj 2010/11/29 12:50:37 Done.
35 } 41 }
36 42
37 WebIDBFactory* IndexedDBContext::GetIDBFactory() { 43 WebIDBFactory* IndexedDBContext::GetIDBFactory() {
38 if (!idb_factory_.get()) 44 if (!idb_factory_.get())
39 idb_factory_.reset(WebIDBFactory::create()); 45 idb_factory_.reset(WebIDBFactory::create());
40 DCHECK(idb_factory_.get()); 46 DCHECK(idb_factory_.get());
41 return idb_factory_.get(); 47 return idb_factory_.get();
42 } 48 }
43 49
44 FilePath IndexedDBContext::GetIndexedDBFilePath( 50 FilePath IndexedDBContext::GetIndexedDBFilePath(
45 const string16& origin_id) const { 51 const string16& origin_id) const {
46 FilePath storage_dir = webkit_context_->data_path().Append(
47 kIndexedDBDirectory);
48 FilePath::StringType id = webkit_glue::WebStringToFilePathString(origin_id); 52 FilePath::StringType id = webkit_glue::WebStringToFilePathString(origin_id);
49 return storage_dir.Append(id.append(kIndexedDBExtension)); 53 return data_path_;
jochen (gone - plz use gerrit) 2010/11/29 10:45:24 this method should return the complete filename, n
pastarmovj 2010/11/29 12:50:37 Done. Sorry this was a mistake while I was cleanin
50 } 54 }
51 55
52 // static 56 void IndexedDBContext::ClearLocalState(const FilePath& indexeddb_path,
53 void IndexedDBContext::ClearLocalState(const FilePath& profile_path,
54 const char* url_scheme_to_be_skipped) { 57 const char* url_scheme_to_be_skipped) {
55 file_util::FileEnumerator file_enumerator(profile_path.Append( 58 file_util::FileEnumerator file_enumerator(
56 kIndexedDBDirectory), false, file_util::FileEnumerator::FILES); 59 indexeddb_path, false, file_util::FileEnumerator::FILES);
57 // TODO(pastarmovj): We might need to consider exchanging this loop for 60 // TODO(pastarmovj): We might need to consider exchanging this loop for
58 // something more efficient in the future. 61 // something more efficient in the future.
59 for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); 62 for (FilePath file_path = file_enumerator.Next(); !file_path.empty();
60 file_path = file_enumerator.Next()) { 63 file_path = file_enumerator.Next()) {
61 if (file_path.Extension() != IndexedDBContext::kIndexedDBExtension) 64 if (file_path.Extension() != IndexedDBContext::kIndexedDBExtension)
62 continue; 65 continue;
63 WebSecurityOrigin origin = 66 WebSecurityOrigin origin =
64 WebSecurityOrigin::createFromDatabaseIdentifier( 67 WebSecurityOrigin::createFromDatabaseIdentifier(
65 webkit_glue::FilePathToWebString(file_path.BaseName())); 68 webkit_glue::FilePathToWebString(file_path.BaseName()));
66 if (!EqualsASCII(origin.protocol(), url_scheme_to_be_skipped)) 69 if (!EqualsASCII(origin.protocol(), url_scheme_to_be_skipped))
67 file_util::Delete(file_path, false); 70 file_util::Delete(file_path, false);
68 } 71 }
69 } 72 }
70 73
71 void IndexedDBContext::DeleteIndexedDBFile(const FilePath& file_path) { 74 void IndexedDBContext::DeleteIndexedDBFile(const FilePath& file_path) {
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT));
73 // TODO(pastarmovj): Close all database connections that use that file. 76 // TODO(pastarmovj): Close all database connections that use that file.
74 file_util::Delete(file_path, false); 77 file_util::Delete(file_path, false);
75 } 78 }
76 79
77 void IndexedDBContext::DeleteIndexedDBForOrigin(const string16& origin_id) { 80 void IndexedDBContext::DeleteIndexedDBForOrigin(const string16& origin_id) {
78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT));
79 // TODO(pastarmovj): Remove this check once we are safe to delete any time. 82 // TODO(pastarmovj): Remove this check once we are safe to delete any time.
80 FilePath idb_file = GetIndexedDBFilePath(origin_id); 83 FilePath idb_file = GetIndexedDBFilePath(origin_id);
81 DCHECK_EQ(idb_file.BaseName().value().substr(0, strlen("chrome-extension")), 84 DCHECK_EQ(idb_file.BaseName().value().substr(0, strlen("chrome-extension")),
82 FILE_PATH_LITERAL("chrome-extension")); 85 FILE_PATH_LITERAL("chrome-extension"));
83 DeleteIndexedDBFile(GetIndexedDBFilePath(origin_id)); 86 DeleteIndexedDBFile(GetIndexedDBFilePath(origin_id));
84 } 87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698