| 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 "chrome/browser/icon_loader.h" | 5 #include "chrome/browser/icon_loader.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "chrome/browser/icon_manager.h" |
| 9 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 10 | 11 |
| 11 using content::BrowserThread; | 12 using content::BrowserThread; |
| 12 | 13 |
| 13 IconLoader::IconLoader(const IconGroupID& group, IconSize size, | 14 IconLoader::IconLoader(const base::FilePath& file_path, IconSize size, |
| 14 Delegate* delegate) | 15 Delegate* delegate) |
| 15 : target_message_loop_(NULL), | 16 : target_message_loop_(NULL), |
| 16 group_(group), | 17 file_path_(file_path), |
| 17 icon_size_(size), | 18 icon_size_(size), |
| 18 image_(NULL), | 19 image_(NULL), |
| 19 delegate_(delegate) { | 20 delegate_(delegate) { |
| 20 } | 21 } |
| 21 | 22 |
| 22 IconLoader::~IconLoader() { | 23 IconLoader::~IconLoader() { |
| 23 } | 24 } |
| 24 | 25 |
| 25 void IconLoader::Start() { | 26 void IconLoader::Start() { |
| 26 target_message_loop_ = base::MessageLoopProxy::current(); | 27 target_message_loop_ = base::MessageLoopProxy::current(); |
| 27 | 28 |
| 28 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 29 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, |
| 29 base::Bind(&IconLoader::ReadIcon, this)); | 30 base::Bind(&IconLoader::ReadGroup, this), |
| 31 base::Bind(&IconLoader::OnReadGroup, this)); |
| 32 } |
| 33 |
| 34 void IconLoader::ReadGroup() { |
| 35 group_ = IconManager::ReadGroupIDFromFilepath(file_path_); |
| 36 } |
| 37 |
| 38 void IconLoader::OnReadGroup() { |
| 39 if (!delegate_->OnGroupLoaded(this, group_)) { |
| 40 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 41 base::Bind(&IconLoader::ReadIcon, this)); |
| 42 } |
| 30 } | 43 } |
| 31 | 44 |
| 32 void IconLoader::NotifyDelegate() { | 45 void IconLoader::NotifyDelegate() { |
| 33 // If the delegate takes ownership of the Image, release it from the scoped | 46 // If the delegate takes ownership of the Image, release it from the scoped |
| 34 // pointer. | 47 // pointer. |
| 35 if (delegate_->OnImageLoaded(this, image_.get())) | 48 if (delegate_->OnImageLoaded(this, image_.get(), group_)) |
| 36 ignore_result(image_.release()); // Can't ignore return value. | 49 ignore_result(image_.release()); // Can't ignore return value. |
| 37 } | 50 } |
| OLD | NEW |