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

Side by Side Diff: webkit/dom_storage/dom_storage_context.cc

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "webkit/dom_storage/dom_storage_context.h" 5 #include "webkit/dom_storage/dom_storage_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/guid.h" 10 #include "base/guid.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "webkit/dom_storage/dom_storage_area.h" 13 #include "webkit/dom_storage/dom_storage_area.h"
14 #include "webkit/dom_storage/dom_storage_database.h" 14 #include "webkit/dom_storage/dom_storage_database.h"
15 #include "webkit/dom_storage/dom_storage_namespace.h" 15 #include "webkit/dom_storage/dom_storage_namespace.h"
16 #include "webkit/dom_storage/dom_storage_task_runner.h" 16 #include "webkit/dom_storage/dom_storage_task_runner.h"
17 #include "webkit/dom_storage/dom_storage_types.h" 17 #include "webkit/dom_storage/dom_storage_types.h"
18 #include "webkit/dom_storage/session_storage_database.h" 18 #include "webkit/dom_storage/session_storage_database.h"
19 #include "webkit/quota/special_storage_policy.h" 19 #include "webkit/quota/special_storage_policy.h"
20 20
21 using file_util::FileEnumerator; 21 using file_util::FileEnumerator;
22 22
23 namespace dom_storage { 23 namespace dom_storage {
24 24
25 static const int kSessionStoraceScavengingSeconds = 60; 25 static const int kSessionStoraceScavengingSeconds = 60;
26 26
27 DomStorageContext::DomStorageContext( 27 DomStorageContext::DomStorageContext(
28 const FilePath& localstorage_directory, 28 const base::FilePath& localstorage_directory,
29 const FilePath& sessionstorage_directory, 29 const base::FilePath& sessionstorage_directory,
30 quota::SpecialStoragePolicy* special_storage_policy, 30 quota::SpecialStoragePolicy* special_storage_policy,
31 DomStorageTaskRunner* task_runner) 31 DomStorageTaskRunner* task_runner)
32 : localstorage_directory_(localstorage_directory), 32 : localstorage_directory_(localstorage_directory),
33 sessionstorage_directory_(sessionstorage_directory), 33 sessionstorage_directory_(sessionstorage_directory),
34 task_runner_(task_runner), 34 task_runner_(task_runner),
35 is_shutdown_(false), 35 is_shutdown_(false),
36 force_keep_session_state_(false), 36 force_keep_session_state_(false),
37 special_storage_policy_(special_storage_policy), 37 special_storage_policy_(special_storage_policy),
38 scavenging_started_(false) { 38 scavenging_started_(false) {
39 // AtomicSequenceNum starts at 0 but we want to start session 39 // AtomicSequenceNum starts at 0 but we want to start session
(...skipping 22 matching lines...) Expand all
62 int64 namespace_id) { 62 int64 namespace_id) {
63 if (is_shutdown_) 63 if (is_shutdown_)
64 return NULL; 64 return NULL;
65 StorageNamespaceMap::iterator found = namespaces_.find(namespace_id); 65 StorageNamespaceMap::iterator found = namespaces_.find(namespace_id);
66 if (found == namespaces_.end()) { 66 if (found == namespaces_.end()) {
67 if (namespace_id == kLocalStorageNamespaceId) { 67 if (namespace_id == kLocalStorageNamespaceId) {
68 if (!localstorage_directory_.empty()) { 68 if (!localstorage_directory_.empty()) {
69 if (!file_util::CreateDirectory(localstorage_directory_)) { 69 if (!file_util::CreateDirectory(localstorage_directory_)) {
70 LOG(ERROR) << "Failed to create 'Local Storage' directory," 70 LOG(ERROR) << "Failed to create 'Local Storage' directory,"
71 " falling back to in-memory only."; 71 " falling back to in-memory only.";
72 localstorage_directory_ = FilePath(); 72 localstorage_directory_ = base::FilePath();
73 } 73 }
74 } 74 }
75 DomStorageNamespace* local = 75 DomStorageNamespace* local =
76 new DomStorageNamespace(localstorage_directory_, task_runner_); 76 new DomStorageNamespace(localstorage_directory_, task_runner_);
77 namespaces_[kLocalStorageNamespaceId] = local; 77 namespaces_[kLocalStorageNamespaceId] = local;
78 return local; 78 return local;
79 } 79 }
80 return NULL; 80 return NULL;
81 } 81 }
82 return found->second; 82 return found->second;
83 } 83 }
84 84
85 void DomStorageContext::GetLocalStorageUsage( 85 void DomStorageContext::GetLocalStorageUsage(
86 std::vector<LocalStorageUsageInfo>* infos, 86 std::vector<LocalStorageUsageInfo>* infos,
87 bool include_file_info) { 87 bool include_file_info) {
88 if (localstorage_directory_.empty()) 88 if (localstorage_directory_.empty())
89 return; 89 return;
90 FileEnumerator enumerator(localstorage_directory_, false, 90 FileEnumerator enumerator(localstorage_directory_, false,
91 FileEnumerator::FILES); 91 FileEnumerator::FILES);
92 for (FilePath path = enumerator.Next(); !path.empty(); 92 for (base::FilePath path = enumerator.Next(); !path.empty();
93 path = enumerator.Next()) { 93 path = enumerator.Next()) {
94 if (path.MatchesExtension(DomStorageArea::kDatabaseFileExtension)) { 94 if (path.MatchesExtension(DomStorageArea::kDatabaseFileExtension)) {
95 LocalStorageUsageInfo info; 95 LocalStorageUsageInfo info;
96 info.origin = DomStorageArea::OriginFromDatabaseFileName(path); 96 info.origin = DomStorageArea::OriginFromDatabaseFileName(path);
97 if (include_file_info) { 97 if (include_file_info) {
98 FileEnumerator::FindInfo find_info; 98 FileEnumerator::FindInfo find_info;
99 enumerator.GetFindInfo(&find_info); 99 enumerator.GetFindInfo(&find_info);
100 info.data_size = FileEnumerator::GetFilesize(find_info); 100 info.data_size = FileEnumerator::GetFilesize(find_info);
101 info.last_modified = FileEnumerator::GetLastModifiedTime(find_info); 101 info.last_modified = FileEnumerator::GetLastModifiedTime(find_info);
102 } 102 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 const bool kDontIncludeFileInfo = false; 306 const bool kDontIncludeFileInfo = false;
307 GetLocalStorageUsage(&infos, kDontIncludeFileInfo); 307 GetLocalStorageUsage(&infos, kDontIncludeFileInfo);
308 for (size_t i = 0; i < infos.size(); ++i) { 308 for (size_t i = 0; i < infos.size(); ++i) {
309 const GURL& origin = infos[i].origin; 309 const GURL& origin = infos[i].origin;
310 if (special_storage_policy_->IsStorageProtected(origin)) 310 if (special_storage_policy_->IsStorageProtected(origin))
311 continue; 311 continue;
312 if (!special_storage_policy_->IsStorageSessionOnly(origin)) 312 if (!special_storage_policy_->IsStorageSessionOnly(origin))
313 continue; 313 continue;
314 314
315 const bool kNotRecursive = false; 315 const bool kNotRecursive = false;
316 FilePath database_file_path = localstorage_directory_.Append( 316 base::FilePath database_file_path = localstorage_directory_.Append(
317 DomStorageArea::DatabaseFileNameFromOrigin(origin)); 317 DomStorageArea::DatabaseFileNameFromOrigin(origin));
318 file_util::Delete(database_file_path, kNotRecursive); 318 file_util::Delete(database_file_path, kNotRecursive);
319 file_util::Delete( 319 file_util::Delete(
320 DomStorageDatabase::GetJournalFilePath(database_file_path), 320 DomStorageDatabase::GetJournalFilePath(database_file_path),
321 kNotRecursive); 321 kNotRecursive);
322 } 322 }
323 } 323 }
324 if (session_storage_database_.get()) { 324 if (session_storage_database_.get()) {
325 std::vector<SessionStorageUsageInfo> infos; 325 std::vector<SessionStorageUsageInfo> infos;
326 GetSessionStorageUsage(&infos); 326 GetSessionStorageUsage(&infos);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 if (!deletable_persistent_namespace_ids_.empty()) { 415 if (!deletable_persistent_namespace_ids_.empty()) {
416 task_runner_->PostDelayedTask( 416 task_runner_->PostDelayedTask(
417 FROM_HERE, base::Bind( 417 FROM_HERE, base::Bind(
418 &DomStorageContext::DeleteNextUnusedNamespace, 418 &DomStorageContext::DeleteNextUnusedNamespace,
419 this), 419 this),
420 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); 420 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds));
421 } 421 }
422 } 422 }
423 423
424 } // namespace dom_storage 424 } // namespace dom_storage
OLDNEW
« no previous file with comments | « webkit/dom_storage/dom_storage_context.h ('k') | webkit/dom_storage/dom_storage_context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698