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

Side by Side Diff: chrome/browser/extensions/api/media_galleries/media_galleries_api.cc

Issue 174013009: Add end to end test for Media galleries scan API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mock Created 6 years, 10 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
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 // Implements the Chrome Extensions Media Galleries API. 5 // Implements the Chrome Extensions Media Galleries API.
6 6
7 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h" 7 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h"
8 8
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "apps/app_window.h" 13 #include "apps/app_window.h"
14 #include "apps/app_window_registry.h" 14 #include "apps/app_window_registry.h"
15 #include "base/callback.h"
15 #include "base/lazy_instance.h" 16 #include "base/lazy_instance.h"
16 #include "base/platform_file.h" 17 #include "base/platform_file.h"
17 #include "base/stl_util.h" 18 #include "base/stl_util.h"
18 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
20 #include "base/values.h" 21 #include "base/values.h"
21 #include "chrome/browser/browser_process.h" 22 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/extensions/api/file_system/file_system_api.h" 23 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
23 #include "chrome/browser/extensions/blob_reader.h" 24 #include "chrome/browser/extensions/blob_reader.h"
24 #include "chrome/browser/extensions/extension_tab_util.h" 25 #include "chrome/browser/extensions/extension_tab_util.h"
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 // We don't fire a scan progress error here, as it would be unintuitive. 692 // We don't fire a scan progress error here, as it would be unintuitive.
692 return false; 693 return false;
693 } 694 }
694 if (!user_gesture()) 695 if (!user_gesture())
695 return false; 696 return false;
696 697
697 return Setup(GetProfile(), &error_, base::Bind( 698 return Setup(GetProfile(), &error_, base::Bind(
698 &MediaGalleriesAddScanResultsFunction::OnPreferencesInit, this)); 699 &MediaGalleriesAddScanResultsFunction::OnPreferencesInit, this));
699 } 700 }
700 701
702 MediaGalleriesScanResultDialogController*
703 MediaGalleriesAddScanResultsFunction::MakeDialog(
704 content::WebContents* web_contents,
705 const extensions::Extension& extension,
706 const base::Closure& on_finish) {
707 // Controller will delete itself.
708 return new MediaGalleriesScanResultDialogController(web_contents, extension,
709 on_finish);
710 }
711
701 void MediaGalleriesAddScanResultsFunction::OnPreferencesInit() { 712 void MediaGalleriesAddScanResultsFunction::OnPreferencesInit() {
702 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 713 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
703 const Extension* extension = GetExtension(); 714 const Extension* extension = GetExtension();
704 MediaGalleriesPreferences* preferences = 715 MediaGalleriesPreferences* preferences =
705 media_file_system_registry()->GetPreferences(GetProfile()); 716 media_file_system_registry()->GetPreferences(GetProfile());
706 if (MediaGalleriesScanResultDialogController::ScanResultCountForExtension( 717 if (MediaGalleriesScanResultDialogController::ScanResultCountForExtension(
707 preferences, extension) == 0) { 718 preferences, extension) == 0) {
708 GetAndReturnGalleries(); 719 GetAndReturnGalleries();
709 return; 720 return;
710 } 721 }
711 722
712 WebContents* contents = 723 WebContents* contents =
713 GetWebContents(render_view_host(), GetProfile(), extension->id()); 724 GetWebContents(render_view_host(), GetProfile(), extension->id());
714 if (!contents) { 725 if (!contents) {
715 SendResponse(false); 726 SendResponse(false);
716 return; 727 return;
717 } 728 }
718 729
719 // Controller will delete itself.
720 base::Closure cb = base::Bind( 730 base::Closure cb = base::Bind(
721 &MediaGalleriesAddScanResultsFunction::GetAndReturnGalleries, this); 731 &MediaGalleriesAddScanResultsFunction::GetAndReturnGalleries, this);
722 new MediaGalleriesScanResultDialogController(contents, *extension, cb); 732 MakeDialog(contents, *extension, cb);
723 } 733 }
724 734
725 void MediaGalleriesAddScanResultsFunction::GetAndReturnGalleries() { 735 void MediaGalleriesAddScanResultsFunction::GetAndReturnGalleries() {
726 if (!render_view_host()) { 736 if (!render_view_host()) {
727 ReturnGalleries(std::vector<MediaFileSystemInfo>()); 737 ReturnGalleries(std::vector<MediaFileSystemInfo>());
728 return; 738 return;
729 } 739 }
730 MediaFileSystemRegistry* registry = media_file_system_registry(); 740 MediaFileSystemRegistry* registry = media_file_system_registry();
731 DCHECK(registry->GetPreferences(GetProfile())->IsInitialized()); 741 DCHECK(registry->GetPreferences(GetProfile())->IsInitialized());
732 registry->GetMediaFileSystemsForExtension( 742 registry->GetMediaFileSystemsForExtension(
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 if (mime_type_sniffed) 808 if (mime_type_sniffed)
799 metadata.mime_type = mime_type; 809 metadata.mime_type = mime_type;
800 810
801 // TODO(tommycli): Kick off SafeMediaMetadataParser if |mime_type_only| false. 811 // TODO(tommycli): Kick off SafeMediaMetadataParser if |mime_type_only| false.
802 812
803 SetResult(metadata.ToValue().release()); 813 SetResult(metadata.ToValue().release());
804 SendResponse(true); 814 SendResponse(true);
805 } 815 }
806 816
807 } // namespace extensions 817 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698