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

Side by Side Diff: webkit/tools/test_shell/test_shell_webblobregistry_impl.cc

Issue 10834386: Cleanup Blob code dependency (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
« no previous file with comments | « webkit/blob/blob_data.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/tools/test_shell/test_shell_webblobregistry_impl.h" 5 #include "webkit/tools/test_shell/test_shell_webblobregistry_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "googleurl/src/gurl.h" 9 #include "googleurl/src/gurl.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebBlobData. h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebBlobData. h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
12 #include "webkit/blob/blob_data.h" 12 #include "webkit/blob/blob_data.h"
13 #include "webkit/blob/blob_storage_controller.h" 13 #include "webkit/blob/blob_storage_controller.h"
14 #include "webkit/glue/webkit_glue.h"
14 15
15 using WebKit::WebBlobData; 16 using WebKit::WebBlobData;
16 using WebKit::WebURL; 17 using WebKit::WebURL;
17 using webkit_blob::BlobData; 18 using webkit_blob::BlobData;
18 19
19 namespace { 20 namespace {
20 21
21 MessageLoop* g_io_thread; 22 MessageLoop* g_io_thread;
22 webkit_blob::BlobStorageController* g_blob_storage_controller; 23 webkit_blob::BlobStorageController* g_blob_storage_controller;
23 24
25 // Creates a new BlobData from WebBlobData.
26 BlobData* NewBlobData(const WebBlobData& data) {
27 BlobData* blob = new BlobData;
28 size_t i = 0;
29 WebBlobData::Item item;
30 while (data.itemAt(i++, item)) {
31 switch (item.type) {
32 case WebBlobData::Item::TypeData:
33 if (!item.data.isEmpty()) {
34 // WebBlobData does not allow partial data.
35 DCHECK(!item.offset && item.length == -1);
36 blob->AppendData(item.data);
37 }
38 break;
39 case WebBlobData::Item::TypeFile:
40 if (item.length) {
41 blob->AppendFile(
42 webkit_glue::WebStringToFilePath(item.filePath),
43 static_cast<uint64>(item.offset),
44 static_cast<uint64>(item.length),
45 base::Time::FromDoubleT(item.expectedModificationTime));
46 }
47 break;
48 case WebBlobData::Item::TypeBlob:
49 if (item.length) {
50 blob->AppendBlob(
51 item.blobURL,
52 static_cast<uint64>(item.offset),
53 static_cast<uint64>(item.length));
54 }
55 break;
56 default:
57 NOTREACHED();
58 }
59 }
60 blob->set_content_type(data.contentType().utf8().data());
61 blob->set_content_disposition(data.contentDisposition().utf8().data());
62 return blob;
63 }
64
24 } // namespace 65 } // namespace
25 66
26 /* static */ 67 /* static */
27 void TestShellWebBlobRegistryImpl::InitializeOnIOThread( 68 void TestShellWebBlobRegistryImpl::InitializeOnIOThread(
28 webkit_blob::BlobStorageController* blob_storage_controller) { 69 webkit_blob::BlobStorageController* blob_storage_controller) {
29 g_io_thread = MessageLoop::current(); 70 g_io_thread = MessageLoop::current();
30 g_blob_storage_controller = blob_storage_controller; 71 g_blob_storage_controller = blob_storage_controller;
31 } 72 }
32 73
33 /* static */ 74 /* static */
34 void TestShellWebBlobRegistryImpl::Cleanup() { 75 void TestShellWebBlobRegistryImpl::Cleanup() {
35 g_io_thread = NULL; 76 g_io_thread = NULL;
36 g_blob_storage_controller = NULL; 77 g_blob_storage_controller = NULL;
37 } 78 }
38 79
39 void TestShellWebBlobRegistryImpl::registerBlobURL( 80 void TestShellWebBlobRegistryImpl::registerBlobURL(
40 const WebURL& url, WebBlobData& data) { 81 const WebURL& url, WebBlobData& data) {
41 DCHECK(g_io_thread); 82 DCHECK(g_io_thread);
42 GURL thread_safe_url = url; // WebURL uses refcounted strings. 83 GURL thread_safe_url = url; // WebURL uses refcounted strings.
43 g_io_thread->PostTask(FROM_HERE, base::Bind( 84 g_io_thread->PostTask(FROM_HERE, base::Bind(
44 &TestShellWebBlobRegistryImpl::AddFinishedBlob, this, 85 &TestShellWebBlobRegistryImpl::AddFinishedBlob, this,
45 thread_safe_url, make_scoped_refptr(new BlobData(data)))); 86 thread_safe_url, make_scoped_refptr(NewBlobData(data))));
46 } 87 }
47 88
48 void TestShellWebBlobRegistryImpl::registerBlobURL( 89 void TestShellWebBlobRegistryImpl::registerBlobURL(
49 const WebURL& url, const WebURL& src_url) { 90 const WebURL& url, const WebURL& src_url) {
50 DCHECK(g_io_thread); 91 DCHECK(g_io_thread);
51 GURL thread_safe_url = url; 92 GURL thread_safe_url = url;
52 GURL thread_safe_src_url = src_url; 93 GURL thread_safe_src_url = src_url;
53 g_io_thread->PostTask(FROM_HERE, base::Bind( 94 g_io_thread->PostTask(FROM_HERE, base::Bind(
54 &TestShellWebBlobRegistryImpl::CloneBlob, this, 95 &TestShellWebBlobRegistryImpl::CloneBlob, this,
55 thread_safe_url, thread_safe_src_url)); 96 thread_safe_url, thread_safe_src_url));
(...skipping 18 matching lines...) Expand all
74 void TestShellWebBlobRegistryImpl::CloneBlob( 115 void TestShellWebBlobRegistryImpl::CloneBlob(
75 const GURL& url, const GURL& src_url) { 116 const GURL& url, const GURL& src_url) {
76 DCHECK(g_blob_storage_controller); 117 DCHECK(g_blob_storage_controller);
77 g_blob_storage_controller->CloneBlob(url, src_url); 118 g_blob_storage_controller->CloneBlob(url, src_url);
78 } 119 }
79 120
80 void TestShellWebBlobRegistryImpl::RemoveBlob(const GURL& url) { 121 void TestShellWebBlobRegistryImpl::RemoveBlob(const GURL& url) {
81 DCHECK(g_blob_storage_controller); 122 DCHECK(g_blob_storage_controller);
82 g_blob_storage_controller->RemoveBlob(url); 123 g_blob_storage_controller->RemoveBlob(url);
83 } 124 }
OLDNEW
« no previous file with comments | « webkit/blob/blob_data.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698