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

Side by Side Diff: content/browser/fileapi/chrome_blob_storage_context.cc

Issue 810403004: [Storage] Blob Storage Refactoring pt 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: memory leak fixed Created 5 years, 11 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
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 "content/browser/fileapi/chrome_blob_storage_context.h" 5 #include "content/browser/fileapi/chrome_blob_storage_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "content/public/browser/blob_handle.h" 9 #include "content/public/browser/blob_handle.h"
10 #include "content/public/browser/browser_context.h" 10 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "storage/browser/blob/blob_data_handle.h" 12 #include "storage/browser/blob/blob_data_handle.h"
13 #include "storage/browser/blob/blob_storage_context.h" 13 #include "storage/browser/blob/blob_storage_context.h"
14 14
15 using base::UserDataAdapter; 15 using base::UserDataAdapter;
16 using storage::BlobStorageContext; 16 using storage::BlobStorageContext;
17 17
18 namespace content { 18 namespace content {
19 19
20 namespace { 20 namespace {
21 21
22 const char kBlobStorageContextKeyName[] = "content_blob_storage_context"; 22 const char kBlobStorageContextKeyName[] = "content_blob_storage_context";
23 23
24 class BlobHandleImpl : public BlobHandle { 24 class BlobHandleImpl : public BlobHandle {
25 public: 25 public:
26 explicit BlobHandleImpl(scoped_ptr<storage::BlobDataHandle> handle) 26 explicit BlobHandleImpl(scoped_ptr<storage::BlobDataSnapshotHandle> handle)
27 : handle_(handle.Pass()) { 27 : handle_(handle.Pass()) {}
28 }
29 28
30 ~BlobHandleImpl() override {} 29 ~BlobHandleImpl() override {}
31 30
32 std::string GetUUID() override { return handle_->uuid(); } 31 std::string GetUUID() override { return handle_->uuid(); }
33 32
34 private: 33 private:
35 scoped_ptr<storage::BlobDataHandle> handle_; 34 scoped_ptr<storage::BlobDataSnapshotHandle> handle_;
michaeln 2015/01/16 00:09:09 for this particular class we only want to keep the
dmurph 2015/01/16 23:45:56 Right, we want to keep the handle around though, r
36 }; 35 };
37 36
38 } // namespace 37 } // namespace
39 38
40 ChromeBlobStorageContext::ChromeBlobStorageContext() {} 39 ChromeBlobStorageContext::ChromeBlobStorageContext() {}
41 40
42 ChromeBlobStorageContext* ChromeBlobStorageContext::GetFor( 41 ChromeBlobStorageContext* ChromeBlobStorageContext::GetFor(
43 BrowserContext* context) { 42 BrowserContext* context) {
44 if (!context->GetUserData(kBlobStorageContextKeyName)) { 43 if (!context->GetUserData(kBlobStorageContextKeyName)) {
45 scoped_refptr<ChromeBlobStorageContext> blob = 44 scoped_refptr<ChromeBlobStorageContext> blob =
(...skipping 16 matching lines...) Expand all
62 void ChromeBlobStorageContext::InitializeOnIOThread() { 61 void ChromeBlobStorageContext::InitializeOnIOThread() {
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
64 context_.reset(new BlobStorageContext()); 63 context_.reset(new BlobStorageContext());
65 } 64 }
66 65
67 scoped_ptr<BlobHandle> ChromeBlobStorageContext::CreateMemoryBackedBlob( 66 scoped_ptr<BlobHandle> ChromeBlobStorageContext::CreateMemoryBackedBlob(
68 const char* data, size_t length) { 67 const char* data, size_t length) {
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
70 69
71 std::string uuid(base::GenerateGUID()); 70 std::string uuid(base::GenerateGUID());
72 scoped_refptr<storage::BlobData> blob_data = new storage::BlobData(uuid); 71 scoped_ptr<storage::BlobDataBuilder> blob_data(
72 new storage::BlobDataBuilder(uuid));
73 blob_data->AppendData(data, length); 73 blob_data->AppendData(data, length);
74 74
75 scoped_ptr<storage::BlobDataHandle> blob_data_handle = 75 scoped_ptr<storage::BlobDataSnapshotHandle> blob_data_handle =
76 context_->AddFinishedBlob(blob_data.get()); 76 context_->AddFinishedBlob(*blob_data.get());
77 if (!blob_data_handle) 77 if (!blob_data_handle)
78 return scoped_ptr<BlobHandle>(); 78 return scoped_ptr<BlobHandle>();
79 79
80 scoped_ptr<BlobHandle> blob_handle( 80 scoped_ptr<BlobHandle> blob_handle(
81 new BlobHandleImpl(blob_data_handle.Pass())); 81 new BlobHandleImpl(blob_data_handle.Pass()));
82 return blob_handle.Pass(); 82 return blob_handle.Pass();
83 } 83 }
84 84
85 ChromeBlobStorageContext::~ChromeBlobStorageContext() {} 85 ChromeBlobStorageContext::~ChromeBlobStorageContext() {}
86 86
87 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { 87 void ChromeBlobStorageContext::DeleteOnCorrectThread() const {
88 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && 88 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) &&
89 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { 89 !BrowserThread::CurrentlyOn(BrowserThread::IO)) {
90 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); 90 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this);
91 return; 91 return;
92 } 92 }
93 delete this; 93 delete this;
94 } 94 }
95 95
96 } // namespace content 96 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698