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

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: Fixed copyright 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_builder.h"
12 #include "storage/browser/blob/blob_data_handle.h" 13 #include "storage/browser/blob/blob_data_handle.h"
13 #include "storage/browser/blob/blob_storage_context.h" 14 #include "storage/browser/blob/blob_storage_context.h"
14 15
15 using base::UserDataAdapter; 16 using base::UserDataAdapter;
16 using storage::BlobStorageContext; 17 using storage::BlobStorageContext;
17 18
18 namespace content { 19 namespace content {
19 20
20 namespace { 21 namespace {
21 22
22 const char kBlobStorageContextKeyName[] = "content_blob_storage_context"; 23 const char kBlobStorageContextKeyName[] = "content_blob_storage_context";
23 24
24 class BlobHandleImpl : public BlobHandle { 25 class BlobHandleImpl : public BlobHandle {
25 public: 26 public:
26 explicit BlobHandleImpl(scoped_ptr<storage::BlobDataHandle> handle) 27 explicit BlobHandleImpl(scoped_ptr<storage::BlobDataHandle> handle)
27 : handle_(handle.Pass()) { 28 : handle_(handle.Pass()) {}
28 }
29 29
30 ~BlobHandleImpl() override {} 30 ~BlobHandleImpl() override {}
31 31
32 std::string GetUUID() override { return handle_->uuid(); } 32 std::string GetUUID() override { return handle_->uuid(); }
33 33
34 private: 34 private:
35 scoped_ptr<storage::BlobDataHandle> handle_; 35 scoped_ptr<storage::BlobDataHandle> handle_;
36 }; 36 };
37 37
38 } // namespace 38 } // namespace
(...skipping 23 matching lines...) Expand all
62 void ChromeBlobStorageContext::InitializeOnIOThread() { 62 void ChromeBlobStorageContext::InitializeOnIOThread() {
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
64 context_.reset(new BlobStorageContext()); 64 context_.reset(new BlobStorageContext());
65 } 65 }
66 66
67 scoped_ptr<BlobHandle> ChromeBlobStorageContext::CreateMemoryBackedBlob( 67 scoped_ptr<BlobHandle> ChromeBlobStorageContext::CreateMemoryBackedBlob(
68 const char* data, size_t length) { 68 const char* data, size_t length) {
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
70 70
71 std::string uuid(base::GenerateGUID()); 71 std::string uuid(base::GenerateGUID());
72 scoped_refptr<storage::BlobData> blob_data = new storage::BlobData(uuid); 72 scoped_ptr<storage::BlobDataBuilder> blob_data_builder(
73 blob_data->AppendData(data, length); 73 new storage::BlobDataBuilder(uuid));
74 blob_data_builder->AppendData(data, length);
74 75
75 scoped_ptr<storage::BlobDataHandle> blob_data_handle = 76 scoped_ptr<storage::BlobDataHandle> blob_data_handle =
76 context_->AddFinishedBlob(blob_data.get()); 77 context_->AddFinishedBlob(*blob_data_builder.get());
77 if (!blob_data_handle) 78 if (!blob_data_handle)
78 return scoped_ptr<BlobHandle>(); 79 return scoped_ptr<BlobHandle>();
79 80
80 scoped_ptr<BlobHandle> blob_handle( 81 scoped_ptr<BlobHandle> blob_handle(
81 new BlobHandleImpl(blob_data_handle.Pass())); 82 new BlobHandleImpl(blob_data_handle.Pass()));
82 return blob_handle.Pass(); 83 return blob_handle.Pass();
83 } 84 }
84 85
85 ChromeBlobStorageContext::~ChromeBlobStorageContext() {} 86 ChromeBlobStorageContext::~ChromeBlobStorageContext() {}
86 87
87 void ChromeBlobStorageContext::DeleteOnCorrectThread() const { 88 void ChromeBlobStorageContext::DeleteOnCorrectThread() const {
88 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && 89 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) &&
89 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { 90 !BrowserThread::CurrentlyOn(BrowserThread::IO)) {
90 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); 91 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this);
91 return; 92 return;
92 } 93 }
93 delete this; 94 delete this;
94 } 95 }
95 96
96 } // namespace content 97 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698