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

Unified Diff: chrome/browser/icon_url_data_manager.h

Issue 3324009: Work in progress implementation of Icon URI scheme. (Closed) Base URL: git://git.chromium.org/chromium.git
Patch Set: Created 10 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/icon_url_data_manager.h
diff --git a/chrome/browser/icon_url_data_manager.h b/chrome/browser/icon_url_data_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..b4fda1d693346429787d4aa6c8d6ef482fe41e37
--- /dev/null
+++ b/chrome/browser/icon_url_data_manager.h
@@ -0,0 +1,185 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_ICON_URL_DATA_MANAGER_H_
+#define CHROME_BROWSER_ICON_URL_DATA_MANAGER_H_
+
+#include <string>
+#include <map>
+
+#include "base/ref_counted_memory.h"
+#include "base/scoped_ptr.h"
+#include "base/singleton.h"
+#include "base/task.h"
+#include "chrome/browser/icon_loader.h"
+#include "net/url_request/url_request_job.h"
+
+class IconURLDataManager;
+
+class URLRequestIconJob : public URLRequestJob {
+ public:
+ typedef int RequestID;
+
+ explicit URLRequestIconJob(URLRequest* request);
+
+ // URLRequestJob implementation.
+ virtual void Start();
+
+ virtual void Kill();
+
+ virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read);
+
+ virtual bool GetMimeType(std::string* mime_type) const;
+
+ void SetMimeType(const std::string& mime_type);
+
+ private:
+ friend class IconURLDataManager;
+
+ virtual ~URLRequestIconJob();
+
+ // Helper for Start(), to let us start asynchronously.
+ // (This pattern is shared by most URLRequestJob implementations.)
+ void StartAsync();
+
+ bool StartRequest();
+
+ void DataAvailable(RefCountedMemory* bytes);
+
+ // Do the actual copy from data_ (the data we're serving) into |buf|.
+ // Separate from ReadRawData so we can handle async I/O.
+ void CompleteRead(net::IOBuffer* buf, int buf_size, int* bytes_read);
+
+ // The actual data we're serving. NULL until it's been fetched.
+ scoped_refptr<RefCountedMemory> data_;
+ // The current offset into the data that we're handing off to our
+ // callers via the Read interfaces.
+ int data_offset_;
+
+ // For async reads, we keep around a pointer to the buffer that
+ // we're reading into.
+ scoped_refptr<net::IOBuffer> pending_buf_;
+
+ int pending_buf_size_;
+
+ std::string mime_type_;
+
+ DISALLOW_COPY_AND_ASSIGN(URLRequestIconJob);
+};
+
+
+// IconURI represents a URI that can be used to resolve an icon URI as
+// specified by http://tools.ietf.org/html/draft-lafayette-icon-uri-scheme-01.
+//
+// iconuri = "icon:" ( fextension / mediatype / "unknown" /
+// "directory" / "parentdir" ) [ ";" size ]
+// fextension = "." 1*token ; File extension
+// mediatype = [ type ":" subtype ] ; Internet media type
+// size = pixels / "small" / "medium" / "large"
+// pixels = 1*digit ; Size of icon in square pixels
+class IconURI {
+ public:
+ // Keyword identifiers for an icon.
+ static const std::string DIRECTORY;
+ static const std::string PARENT_DIRECTORY;
+ static const std::string UNKNOWN;
+
+ // Size identifiers for an icon.
+ static const std::string SMALL_ID;
+ static const std::string MEDIUM_ID;
+ static const std::string LARGE_ID;
+
+ enum IconSizes {
+ SMALL = 16,
+ MEDIUM = 32,
+ LARGE = 64
+ };
+
+ IconURI();
+
+ ~IconURI();
+
+ bool ParseIconURI(const GURL& url);
+
+ // Returns whether the provided URL is a valid icon URI. We return a default
+ // icon image for icon URIs with unresolvable paths.
+ bool IsValid();
+
+ std::string extension() const;
+
+ // Returns the internet content type if specified by the URI.
+ std::string media_type() const;
+
+ std::string keyword() const;
+
+ // For now IconLoader only can load 3 sizes.
+ IconLoader::IconSize GetIconLoaderSize() const;
+
+ // Returns the width/height of the icon.
+ int size() const;
+
+ private:
+ void SetIdentifier(const std::string& identifier);
+
+ void SetExtension(const std::string& ext);
+
+ // Need to map media type to an extension for lookup.
+ void SetMediaType(const std::string& media_type);
+
+ // Different platforms support different icon sizes. Icons MUST be scaled to
+ // the appropriate size if not available natively.
+ void SetSize(const std::string& size_str);
+
+ GURL url_;
+ std::string extension_;
+ std::string media_type_;
+ std::string keyword_;
+ int size_;
+};
+
+
+class IconJobSource;
+
+class IconURLDataManager {
+ public:
+ typedef int RequestID;
+
+ IconURLDataManager();
+
+ ~IconURLDataManager();
+
+ static URLRequestJob* Factory(URLRequest* request, const std::string& scheme);
+
+ void StartDataRequest(const IconURI& icon_uri,
+ URLRequestIconJob* job);
+
+ void DataAvailable(RequestID request_id,
+ scoped_refptr<RefCountedMemory> bytes);
+
+ void RemoveRequest(URLRequestIconJob* job);
+
+ bool HasPendingJob(URLRequestIconJob* job) const;
+
+ private:
+ scoped_refptr<IconJobSource> data_source_;
+
+ // The ID we'll use for the next request we receive.
+ RequestID next_request_id_;
+
+ // All pending URLRequestIconJobs, keyed by ID of the request.
+ // URLRequestChromeJob calls into this object when it's constructed and
+ // destructed to ensure that the pointers in this map remain valid.
+ typedef std::map<RequestID, URLRequestIconJob*> PendingRequestMap;
+ PendingRequestMap pending_requests_;
+
+ friend struct DefaultSingletonTraits<IconURLDataManager>;
+ DISALLOW_COPY_AND_ASSIGN(IconURLDataManager);
+};
+
+DISABLE_RUNNABLE_METHOD_REFCOUNT(IconURLDataManager);
+
+// Used to initialize the IconURLDataManager on the UI thread.
+void RegisterURLRequestIconJob();
+
+#endif // CHROME_BROWSER_ICON_URL_DATA_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698