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 "content/browser/indexed_db/indexed_db_context_impl.h" | 5 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 if (!s.ok()) { | 306 if (!s.ok()) { |
307 LOG(WARNING) << "Failed to delete LevelDB database: " | 307 LOG(WARNING) << "Failed to delete LevelDB database: " |
308 << idb_directory.AsUTF8Unsafe(); | 308 << idb_directory.AsUTF8Unsafe(); |
309 } else { | 309 } else { |
310 // LevelDB does not delete empty directories; work around this. | 310 // LevelDB does not delete empty directories; work around this. |
311 // TODO(jsbell): Remove when upstream bug is fixed. | 311 // TODO(jsbell): Remove when upstream bug is fixed. |
312 // https://code.google.com/p/leveldb/issues/detail?id=209 | 312 // https://code.google.com/p/leveldb/issues/detail?id=209 |
313 const bool kNonRecursive = false; | 313 const bool kNonRecursive = false; |
314 base::DeleteFile(idb_directory, kNonRecursive); | 314 base::DeleteFile(idb_directory, kNonRecursive); |
315 } | 315 } |
316 base::DeleteFile(GetBlobPath(storage::GetIdentifierFromOrigin(origin_url)), | 316 |
317 true /* recursive */); | |
318 QueryDiskAndUpdateQuotaUsage(origin_url); | 317 QueryDiskAndUpdateQuotaUsage(origin_url); |
319 if (s.ok()) { | 318 if (s.ok()) { |
320 RemoveFromOriginSet(origin_url); | 319 RemoveFromOriginSet(origin_url); |
321 origin_size_map_.erase(origin_url); | 320 origin_size_map_.erase(origin_url); |
322 space_available_map_.erase(origin_url); | 321 space_available_map_.erase(origin_url); |
323 } | 322 } |
324 } | 323 } |
325 | 324 |
325 void IndexedDBContextImpl::CopyOriginData(const GURL& origin_url, | |
326 IndexedDBContext* dest_context) { | |
327 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); | |
328 | |
329 if (data_path_.empty() || !IsInOriginSet(origin_url)) | |
330 return; | |
331 | |
332 IndexedDBContextImpl* dest_context_impl = | |
333 static_cast<IndexedDBContextImpl*>(dest_context); | |
334 | |
335 ForceClose(origin_url, FORCE_CLOSE_COPY_ORIGIN); | |
336 std::string origin_id = storage::GetIdentifierFromOrigin(origin_url); | |
337 | |
338 // Make sure we're not about to delete our own database. | |
339 CHECK(dest_context_impl->data_path() != data_path()); | |
cmumford
2015/01/06 15:30:26
CHECK_NE
| |
340 | |
341 // Delete any existing storage paths in the destination context. | |
342 // A previously failed migration may have left behind partially copied | |
343 // directories. | |
344 for (const base::FilePath& dest_path : | |
345 dest_context_impl->GetStoragePaths(origin_url)) { | |
346 if (base::PathExists(dest_path)) { | |
cmumford
2015/01/06 15:30:27
Nit: consider just calling DeleteFile(), and ignor
| |
347 base::DeleteFile(dest_path, true); | |
348 } | |
349 } | |
350 | |
351 // Creates the IndexedDB directory in the destination context if it doesn't | |
cmumford
2015/01/06 15:30:26
Comment adds no value - code is obvious.
| |
352 // already exist. | |
353 base::FilePath dest_data_path = dest_context_impl->data_path(); | |
354 if (!base::PathExists(dest_data_path)) { | |
355 base::CreateDirectory(dest_data_path); | |
cmumford
2015/01/06 15:30:27
Consider just calling CreateDirectory and ignoring
| |
356 } | |
357 | |
358 // Copies the storage paths to the destination context. | |
cmumford
2015/01/06 15:30:27
Nit: consider dropping obvious comment.
| |
359 for (const base::FilePath& src_path : GetStoragePaths(origin_url)) { | |
360 if (base::PathExists(src_path)) { | |
361 base::CopyDirectory(src_path, dest_data_path, true); | |
cmumford
2015/01/06 15:30:27
Nit:
Can you make the names congruent? src_data_p
| |
362 } | |
363 } | |
364 } | |
365 | |
326 void IndexedDBContextImpl::ForceClose(const GURL origin_url, | 366 void IndexedDBContextImpl::ForceClose(const GURL origin_url, |
327 ForceCloseReason reason) { | 367 ForceCloseReason reason) { |
328 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); | 368 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); |
329 UMA_HISTOGRAM_ENUMERATION("WebCore.IndexedDB.Context.ForceCloseReason", | 369 UMA_HISTOGRAM_ENUMERATION("WebCore.IndexedDB.Context.ForceCloseReason", |
330 reason, | 370 reason, |
331 FORCE_CLOSE_REASON_MAX); | 371 FORCE_CLOSE_REASON_MAX); |
332 | 372 |
333 if (data_path_.empty() || !IsInOriginSet(origin_url)) | 373 if (data_path_.empty() || !IsInOriginSet(origin_url)) |
334 return; | 374 return; |
335 | 375 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 origin_set_.reset(); | 612 origin_set_.reset(); |
573 origin_size_map_.clear(); | 613 origin_size_map_.clear(); |
574 space_available_map_.clear(); | 614 space_available_map_.clear(); |
575 } | 615 } |
576 | 616 |
577 base::SequencedTaskRunner* IndexedDBContextImpl::TaskRunner() const { | 617 base::SequencedTaskRunner* IndexedDBContextImpl::TaskRunner() const { |
578 return task_runner_.get(); | 618 return task_runner_.get(); |
579 } | 619 } |
580 | 620 |
581 } // namespace content | 621 } // namespace content |
OLD | NEW |