1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/media_galleries/fileapi/picasa_finder.h" 6 7#include "base/files/file_path.h" 8#import "base/mac/foundation_util.h" 9#import "base/mac/scoped_nsobject.h" 10#include "components/policy/core/common/preferences_mac.h" 11#include "content/public/browser/browser_thread.h" 12 13using base::mac::CFCast; 14using base::mac::CFToNSCast; 15using base::mac::NSToCFCast; 16 17namespace picasa { 18 19namespace { 20 21static MacPreferences* g_test_mac_preferences = NULL; 22 23} // namespace 24 25NSString* const kPicasaAppDataPathMacPreferencesKey = @"AppLocalDataPath"; 26 27void SetMacPreferencesForTesting(MacPreferences* preferences) { 28 g_test_mac_preferences = preferences; 29} 30 31base::FilePath GetCustomPicasaAppDataPathFromMacPreferences() { 32 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); 33 34 scoped_ptr<MacPreferences> real_preferences; 35 MacPreferences* prefs = g_test_mac_preferences; 36 if (!prefs) { 37 real_preferences.reset(new MacPreferences()); 38 prefs = real_preferences.get(); 39 } 40 41 CFStringRef picasa_app_id = CFSTR("com.google.picasa"); 42 base::scoped_nsobject<NSString> database_path( 43 CFToNSCast(CFCast<CFStringRef>(prefs->CopyAppValue( 44 NSToCFCast(kPicasaAppDataPathMacPreferencesKey), picasa_app_id)))); 45 46 if (database_path == NULL) 47 return base::FilePath(); 48 49 return base::mac::NSStringToFilePath(database_path.get()); 50} 51 52} // namespace picasa 53