iphoto_data_provider.cc revision 8bcbed890bc3ce4d7a057a8f32cab53fa534672e
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/iphoto_data_provider.h" 6 7#include <map> 8 9#include "base/bind.h" 10#include "base/callback.h" 11#include "base/location.h" 12#include "base/logging.h" 13#include "base/platform_file.h" 14#include "base/threading/thread_restrictions.h" 15#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" 16#include "chrome/browser/media_galleries/fileapi/safe_iapps_library_parser.h" 17#include "content/public/browser/browser_thread.h" 18 19namespace iphoto { 20 21IPhotoDataProvider::IPhotoDataProvider(const base::FilePath& library_path) 22 : iapps::IAppsDataProvider(library_path), 23 weak_factory_(this) {} 24 25IPhotoDataProvider::~IPhotoDataProvider() {} 26 27void IPhotoDataProvider::DoParseLibrary( 28 const base::FilePath& library_path, 29 const ReadyCallback& ready_callback) { 30 xml_parser_ = new iapps::SafeIAppsLibraryParser; 31 xml_parser_->ParseIPhotoLibrary( 32 library_path, 33 base::Bind(&IPhotoDataProvider::OnLibraryParsed, 34 weak_factory_.GetWeakPtr(), 35 ready_callback)); 36} 37 38void IPhotoDataProvider::OnLibraryParsed(const ReadyCallback& ready_callback, 39 bool result, 40 const parser::Library& library) { 41 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); 42 set_valid(result); 43 if (valid()) { 44 library_ = library; 45 } 46 ready_callback.Run(valid()); 47} 48 49} // namespace iphoto 50