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/support/test_webkit_platform_support.h" | 5 #include "webkit/support/test_webkit_platform_support.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/metrics/stats_counters.h" | 9 #include "base/metrics/stats_counters.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 TestWebKitPlatformSupport::createLocalStorageNamespace( | 339 TestWebKitPlatformSupport::createLocalStorageNamespace( |
340 const WebKit::WebString& path, unsigned quota) { | 340 const WebKit::WebString& path, unsigned quota) { |
341 return dom_storage_system_.CreateLocalStorageNamespace(); | 341 return dom_storage_system_.CreateLocalStorageNamespace(); |
342 } | 342 } |
343 | 343 |
344 // Wrap a WebKit::WebIDBFactory to rewrite the data directory to | 344 // Wrap a WebKit::WebIDBFactory to rewrite the data directory to |
345 // a scoped temp directory. In multiprocess Chromium this is rewritten | 345 // a scoped temp directory. In multiprocess Chromium this is rewritten |
346 // to a real profile directory during IPC. | 346 // to a real profile directory during IPC. |
347 class TestWebIDBFactory : public WebKit::WebIDBFactory { | 347 class TestWebIDBFactory : public WebKit::WebIDBFactory { |
348 public: | 348 public: |
349 TestWebIDBFactory() | 349 TestWebIDBFactory() { |
350 : factory_(WebKit::WebIDBFactory::create()) { | |
351 // Create a new temp directory for Indexed DB storage, specific to this | 350 // Create a new temp directory for Indexed DB storage, specific to this |
352 // factory. If this fails, WebKit uses in-memory storage. | 351 // factory. If this fails, WebKit uses in-memory storage. |
353 if (!indexed_db_dir_.CreateUniqueTempDir()) { | 352 if (!indexed_db_dir_.CreateUniqueTempDir()) { |
354 LOG(WARNING) << "Failed to create a temp dir for Indexed DB, " | 353 LOG(WARNING) << "Failed to create a temp dir for Indexed DB, " |
355 "using in-memory storage."; | 354 "using in-memory storage."; |
356 DCHECK(indexed_db_dir_.path().empty()); | 355 DCHECK(indexed_db_dir_.path().empty()); |
357 } | 356 } |
358 data_dir_ = webkit_support::GetAbsoluteWebStringFromUTF8Path( | 357 data_dir_ = webkit_support::GetAbsoluteWebStringFromUTF8Path( |
359 indexed_db_dir_.path().AsUTF8Unsafe()); | 358 indexed_db_dir_.path().AsUTF8Unsafe()); |
| 359 |
| 360 // Lazily construct factory_ so that it gets allocated on the thread where |
| 361 // it will be used. TestWebIDBFactory gets allocated on the main thread. |
360 } | 362 } |
361 | 363 |
362 virtual void getDatabaseNames(WebKit::WebIDBCallbacks* callbacks, | 364 virtual void getDatabaseNames(WebKit::WebIDBCallbacks* callbacks, |
363 const WebKit::WebSecurityOrigin& origin, | 365 const WebKit::WebSecurityOrigin& origin, |
364 WebKit::WebFrame* frame, | 366 WebKit::WebFrame* frame, |
365 const WebString& dataDir) { | 367 const WebString& dataDir) { |
| 368 EnsureFactory(); |
366 factory_->getDatabaseNames(callbacks, origin, frame, | 369 factory_->getDatabaseNames(callbacks, origin, frame, |
367 dataDir.isEmpty() ? data_dir_ : dataDir); | 370 dataDir.isEmpty() ? data_dir_ : dataDir); |
368 } | 371 } |
369 | 372 |
370 virtual void open(const WebString& name, | 373 virtual void open(const WebString& name, |
371 long long version, | 374 long long version, |
372 long long transaction_id, | 375 long long transaction_id, |
373 WebKit::WebIDBCallbacks* callbacks, | 376 WebKit::WebIDBCallbacks* callbacks, |
374 WebKit::WebIDBDatabaseCallbacks* databaseCallbacks, | 377 WebKit::WebIDBDatabaseCallbacks* databaseCallbacks, |
375 const WebKit::WebSecurityOrigin& origin, | 378 const WebKit::WebSecurityOrigin& origin, |
376 WebKit::WebFrame* frame, | 379 WebKit::WebFrame* frame, |
377 const WebString& dataDir) { | 380 const WebString& dataDir) { |
378 factory_->open(name, version, transaction_id, callbacks, | 381 EnsureFactory(); |
379 databaseCallbacks, origin, frame, | 382 factory_->open(name, version, transaction_id, callbacks, |
380 dataDir.isEmpty() ? data_dir_ : dataDir); | 383 databaseCallbacks, origin, frame, |
| 384 dataDir.isEmpty() ? data_dir_ : dataDir); |
381 } | 385 } |
382 | 386 |
383 virtual void deleteDatabase(const WebString& name, | 387 virtual void deleteDatabase(const WebString& name, |
384 WebKit::WebIDBCallbacks* callbacks, | 388 WebKit::WebIDBCallbacks* callbacks, |
385 const WebKit::WebSecurityOrigin& origin, | 389 const WebKit::WebSecurityOrigin& origin, |
386 WebKit::WebFrame* frame, | 390 WebKit::WebFrame* frame, |
387 const WebString& dataDir) { | 391 const WebString& dataDir) { |
| 392 EnsureFactory(); |
388 factory_->deleteDatabase(name, callbacks, origin, frame, | 393 factory_->deleteDatabase(name, callbacks, origin, frame, |
389 dataDir.isEmpty() ? data_dir_ : dataDir); | 394 dataDir.isEmpty() ? data_dir_ : dataDir); |
390 } | 395 } |
391 private: | 396 private: |
| 397 void EnsureFactory() { |
| 398 if (!factory_) |
| 399 factory_.reset(WebKit::WebIDBFactory::create()); |
| 400 } |
| 401 |
392 scoped_ptr<WebIDBFactory> factory_; | 402 scoped_ptr<WebIDBFactory> factory_; |
393 base::ScopedTempDir indexed_db_dir_; | 403 base::ScopedTempDir indexed_db_dir_; |
394 WebString data_dir_; | 404 WebString data_dir_; |
395 }; | 405 }; |
396 | 406 |
397 WebKit::WebIDBFactory* TestWebKitPlatformSupport::idbFactory() { | 407 WebKit::WebIDBFactory* TestWebKitPlatformSupport::idbFactory() { |
398 return new TestWebIDBFactory(); | 408 return new TestWebIDBFactory(); |
399 } | 409 } |
400 | 410 |
401 #if defined(OS_WIN) || defined(OS_MACOSX) | 411 #if defined(OS_WIN) || defined(OS_MACOSX) |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 return 0; | 600 return 0; |
591 } | 601 } |
592 | 602 |
593 WebKit::WebGestureCurve* TestWebKitPlatformSupport::createFlingAnimationCurve( | 603 WebKit::WebGestureCurve* TestWebKitPlatformSupport::createFlingAnimationCurve( |
594 int device_source, | 604 int device_source, |
595 const WebKit::WebFloatPoint& velocity, | 605 const WebKit::WebFloatPoint& velocity, |
596 const WebKit::WebSize& cumulative_scroll) { | 606 const WebKit::WebSize& cumulative_scroll) { |
597 // Caller will retain and release. | 607 // Caller will retain and release. |
598 return new WebGestureCurveMock(velocity, cumulative_scroll); | 608 return new WebGestureCurveMock(velocity, cumulative_scroll); |
599 } | 609 } |
OLD | NEW |