Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / local_discovery / privet_url_fetcher.h
index 1bd66c1..a4c4108 100644 (file)
@@ -7,7 +7,7 @@
 
 #include <string>
 
-#include "base/file_util.h"
+#include "base/files/file_util.h"
 #include "base/memory/weak_ptr.h"
 #include "base/values.h"
 #include "net/url_request/url_fetcher.h"
@@ -42,14 +42,18 @@ class PrivetURLFetcher : public net::URLFetcherDelegate {
    public:
     virtual ~Delegate() {}
 
-    // If you do not implement this method, you will always get a
-    // TOKEN_ERROR error when your token is invalid.
+    // If you do not implement this method for PrivetV1 callers, you will always
+    // get a TOKEN_ERROR error when your token is invalid.
     virtual void OnNeedPrivetToken(
         PrivetURLFetcher* fetcher,
         const TokenCallback& callback);
+
+    // If this returns the empty string, will not send an auth token.
+    virtual std::string GetAuthToken();
+
     virtual void OnError(PrivetURLFetcher* fetcher, ErrorType error) = 0;
     virtual void OnParsedJson(PrivetURLFetcher* fetcher,
-                              const base::DictionaryValue* value,
+                              const base::DictionaryValue& value,
                               bool has_error) = 0;
 
     // If this method is returns true, the data will not be parsed as JSON, and
@@ -62,16 +66,26 @@ class PrivetURLFetcher : public net::URLFetcherDelegate {
   };
 
   PrivetURLFetcher(
-      const std::string& token,
       const GURL& url,
       net::URLFetcher::RequestType request_type,
       net::URLRequestContextGetter* request_context,
       Delegate* delegate);
+
   virtual ~PrivetURLFetcher();
 
+  // net::URLFetcherDelegate methods.
+  virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
+
+  static void SetTokenForHost(const std::string& host,
+                              const std::string& token);
+
+  static void ResetTokenMapForTests();
+
   void DoNotRetryOnTransientError();
 
-  void AllowEmptyPrivetToken();
+  void SendEmptyPrivetToken();
+
+  void V3Mode();
 
   // Set the contents of the Range header. |OnRawData| must return true if this
   // is called.
@@ -89,30 +103,31 @@ class PrivetURLFetcher : public net::URLFetcherDelegate {
   void SetUploadFilePath(const std::string& upload_content_type,
                          const base::FilePath& upload_file_path);
 
-  virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
-  void OnURLFetchCompleteParseData(const net::URLFetcher* source);
-  bool OnURLFetchCompleteDoNotParseData(const net::URLFetcher* source);
-
   const GURL& url() const { return url_fetcher_->GetOriginalURL(); }
   int response_code() const { return url_fetcher_->GetResponseCode(); }
 
  private:
+  void OnURLFetchCompleteParseData(const net::URLFetcher* source);
+  bool OnURLFetchCompleteDoNotParseData(const net::URLFetcher* source);
+
+  std::string GetHostString();  // Get string representing the host.
+  std::string GetPrivetAccessToken();
   void Try();
   void ScheduleRetry(int timeout_seconds);
   bool PrivetErrorTransient(const std::string& error);
   void RequestTokenRefresh();
   void RefreshToken(const std::string& token);
 
-  std::string privet_access_token_;
   GURL url_;
   net::URLFetcher::RequestType request_type_;
   scoped_refptr<net::URLRequestContextGetter> request_context_;
   Delegate* delegate_;
 
   bool do_not_retry_on_transient_error_;
-  bool allow_empty_privet_token_;
+  bool send_empty_privet_token_;
   bool has_byte_range_;
   bool make_response_file_;
+  bool v3_mode_;
 
   int byte_range_start_;
   int byte_range_end_;
@@ -127,27 +142,6 @@ class PrivetURLFetcher : public net::URLFetcherDelegate {
   DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcher);
 };
 
-class PrivetURLFetcherFactory {
- public:
-  explicit PrivetURLFetcherFactory(
-      net::URLRequestContextGetter* request_context);
-  ~PrivetURLFetcherFactory();
-
-  scoped_ptr<PrivetURLFetcher> CreateURLFetcher(
-      const GURL& url,
-      net::URLFetcher::RequestType request_type,
-      PrivetURLFetcher::Delegate* delegate) const;
-
-  void set_token(const std::string& token) { token_ = token; }
-  const std::string& get_token() const { return token_; }
-
- private:
-  scoped_refptr<net::URLRequestContextGetter> request_context_;
-  std::string token_;
-
-  DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcherFactory);
-};
-
 }  // namespace local_discovery
 
 #endif  // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_