1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_IMAGE_SOURCE_H_
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_IMAGE_SOURCE_H_
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "content/public/browser/url_data_source.h"
16 class SequencedTaskRunner;
19 // TODO(michaelpg): Remove dependency on user_manager.
20 namespace user_manager {
26 // TODO(michaelpg): Generalize UserImageLoader for classes like ImageSource.
27 class UserImageLoader;
29 // Data source that reads and decodes an image from the RO file system.
30 class ImageSource : public content::URLDataSource {
33 ~ImageSource() override;
35 // content::URLDataSource implementation.
36 std::string GetSource() const override;
37 void StartDataRequest(
38 const std::string& path,
39 int render_process_id,
41 const content::URLDataSource::GotDataCallback& callback) override;
42 std::string GetMimeType(const std::string& path) const override;
45 void StartOnFileThread(
46 const std::string& path,
47 const content::URLDataSource::GotDataCallback& callback);
49 // Callback for user_manager::UserImageLoader.
51 const content::URLDataSource::GotDataCallback& callback,
52 const user_manager::UserImage& user_image) const;
54 // Checks whether we have allowed the image to be loaded.
55 bool IsWhitelisted(const std::string& path) const;
57 // The background task runner on which file I/O and image decoding are done.
58 scoped_refptr<base::SequencedTaskRunner> task_runner_;
60 scoped_refptr<UserImageLoader> image_loader_;
62 base::WeakPtrFactory<ImageSource> weak_factory_;
64 DISALLOW_COPY_AND_ASSIGN(ImageSource);
67 } // namespace chromeos
69 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_IMAGE_SOURCE_H_