OLD | NEW |
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/time.h" | 10 #include "base/time.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 13 #include "webkit/dom_storage/dom_storage_area.h" |
10 #include "webkit/dom_storage/dom_storage_namespace.h" | 14 #include "webkit/dom_storage/dom_storage_namespace.h" |
11 #include "webkit/dom_storage/dom_storage_task_runner.h" | 15 #include "webkit/dom_storage/dom_storage_task_runner.h" |
12 #include "webkit/dom_storage/dom_storage_types.h" | 16 #include "webkit/dom_storage/dom_storage_types.h" |
| 17 #include "webkit/glue/webkit_glue.h" |
13 #include "webkit/quota/special_storage_policy.h" | 18 #include "webkit/quota/special_storage_policy.h" |
14 | 19 |
| 20 using file_util::FileEnumerator; |
| 21 |
15 namespace dom_storage { | 22 namespace dom_storage { |
16 | 23 |
| 24 DomStorageContext::UsageInfo::UsageInfo() {} |
| 25 DomStorageContext::UsageInfo::~UsageInfo() {} |
| 26 |
17 DomStorageContext::DomStorageContext( | 27 DomStorageContext::DomStorageContext( |
18 const FilePath& directory, | 28 const FilePath& directory, |
19 quota::SpecialStoragePolicy* special_storage_policy, | 29 quota::SpecialStoragePolicy* special_storage_policy, |
20 DomStorageTaskRunner* task_runner) | 30 DomStorageTaskRunner* task_runner) |
21 : directory_(directory), | 31 : directory_(directory), |
22 task_runner_(task_runner) { | 32 task_runner_(task_runner), |
| 33 clear_local_state_(false), |
| 34 save_session_state_(false), |
| 35 special_storage_policy_(special_storage_policy) { |
23 // AtomicSequenceNum starts at 0 but we want to start session | 36 // AtomicSequenceNum starts at 0 but we want to start session |
24 // namespace ids at one since zero is reserved for the | 37 // namespace ids at one since zero is reserved for the |
25 // kLocalStorageNamespaceId. | 38 // kLocalStorageNamespaceId. |
26 session_id_sequence_.GetNext(); | 39 session_id_sequence_.GetNext(); |
27 } | 40 } |
28 | 41 |
29 DomStorageContext::~DomStorageContext() { | 42 DomStorageContext::~DomStorageContext() { |
30 } | 43 } |
31 | 44 |
32 DomStorageNamespace* DomStorageContext::GetStorageNamespace( | 45 DomStorageNamespace* DomStorageContext::GetStorageNamespace( |
33 int64 namespace_id) { | 46 int64 namespace_id) { |
34 StorageNamespaceMap::iterator found = namespaces_.find(namespace_id); | 47 StorageNamespaceMap::iterator found = namespaces_.find(namespace_id); |
35 if (found == namespaces_.end()) { | 48 if (found == namespaces_.end()) { |
36 if (namespace_id == kLocalStorageNamespaceId) { | 49 if (namespace_id == kLocalStorageNamespaceId) { |
37 DomStorageNamespace* local = | 50 DomStorageNamespace* local = |
38 new DomStorageNamespace(directory_, task_runner_); | 51 new DomStorageNamespace(directory_, task_runner_); |
39 namespaces_[kLocalStorageNamespaceId] = local; | 52 namespaces_[kLocalStorageNamespaceId] = local; |
40 return local; | 53 return local; |
41 } | 54 } |
42 return NULL; | 55 return NULL; |
43 } | 56 } |
44 return found->second; | 57 return found->second; |
45 } | 58 } |
46 | 59 |
| 60 void DomStorageContext::GetUsageInfo(std::vector<UsageInfo>* infos) { |
| 61 FileEnumerator enumerator(directory_, false, FileEnumerator::FILES); |
| 62 for (FilePath path = enumerator.Next(); !path.empty(); |
| 63 path = enumerator.Next()) { |
| 64 if (path.MatchesExtension(DomStorageArea::kDatabaseFileExtension)) { |
| 65 UsageInfo info; |
| 66 |
| 67 // Extract origin id from the path and construct a GURL. |
| 68 WebKit::WebString origin_id = webkit_glue::FilePathToWebString( |
| 69 path.BaseName().RemoveExtension()); |
| 70 info.origin = GURL(WebKit::WebSecurityOrigin:: |
| 71 createFromDatabaseIdentifier(origin_id).toString()); |
| 72 |
| 73 FileEnumerator::FindInfo find_info; |
| 74 enumerator.GetFindInfo(&find_info); |
| 75 info.data_size = FileEnumerator::GetFilesize(find_info); |
| 76 info.last_modified = FileEnumerator::GetLastModifiedTime(find_info); |
| 77 |
| 78 infos->push_back(info); |
| 79 } |
| 80 } |
| 81 } |
| 82 |
| 83 void DomStorageContext::DeleteOrigin(const GURL& origin) { |
| 84 // TODO(michaeln): write me |
| 85 } |
| 86 |
| 87 void DomStorageContext::DeleteDataModifiedSince(const base::Time& cutoff) { |
| 88 // TODO(michaeln): write me |
| 89 } |
| 90 |
| 91 void DomStorageContext::PurgeMemory() { |
| 92 // TODO(michaeln): write me |
| 93 } |
| 94 |
| 95 void DomStorageContext::Shutdown() { |
| 96 // TODO(michaeln): write me |
| 97 } |
| 98 |
47 void DomStorageContext::AddEventObserver(EventObserver* observer) { | 99 void DomStorageContext::AddEventObserver(EventObserver* observer) { |
48 event_observers_.AddObserver(observer); | 100 event_observers_.AddObserver(observer); |
49 } | 101 } |
50 | 102 |
51 void DomStorageContext::RemoveEventObserver(EventObserver* observer) { | 103 void DomStorageContext::RemoveEventObserver(EventObserver* observer) { |
52 event_observers_.RemoveObserver(observer); | 104 event_observers_.RemoveObserver(observer); |
53 } | 105 } |
54 | 106 |
55 void DomStorageContext::NotifyItemSet( | 107 void DomStorageContext::NotifyItemSet( |
56 const DomStorageArea* area, | 108 const DomStorageArea* area, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 DCHECK_NE(kLocalStorageNamespaceId, existing_id); | 152 DCHECK_NE(kLocalStorageNamespaceId, existing_id); |
101 DCHECK_NE(kLocalStorageNamespaceId, new_id); | 153 DCHECK_NE(kLocalStorageNamespaceId, new_id); |
102 StorageNamespaceMap::iterator found = namespaces_.find(existing_id); | 154 StorageNamespaceMap::iterator found = namespaces_.find(existing_id); |
103 if (found != namespaces_.end()) | 155 if (found != namespaces_.end()) |
104 namespaces_[new_id] = found->second->Clone(new_id); | 156 namespaces_[new_id] = found->second->Clone(new_id); |
105 else | 157 else |
106 CreateSessionNamespace(new_id); | 158 CreateSessionNamespace(new_id); |
107 } | 159 } |
108 | 160 |
109 } // namespace dom_storage | 161 } // namespace dom_storage |
OLD | NEW |