#include "sync/internal_api/public/attachments/attachment_downloader.h"
#include "url/gurl.h"
+namespace net {
+class HttpResponseHeaders;
+} // namespace net
+
namespace syncer {
// An implementation of AttachmentDownloader.
const OAuth2TokenService::ScopeSet& scopes,
const scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider>&
token_service_provider);
- virtual ~AttachmentDownloaderImpl();
+ ~AttachmentDownloaderImpl() override;
// AttachmentDownloader implementation.
- virtual void DownloadAttachment(const AttachmentId& attachment_id,
- const DownloadCallback& callback) OVERRIDE;
+ void DownloadAttachment(const AttachmentId& attachment_id,
+ const DownloadCallback& callback) override;
// OAuth2TokenService::Consumer implementation.
- virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
- const std::string& access_token,
- const base::Time& expiration_time) OVERRIDE;
- virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
- const GoogleServiceAuthError& error) OVERRIDE;
+ void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
+ const std::string& access_token,
+ const base::Time& expiration_time) override;
+ void OnGetTokenFailure(const OAuth2TokenService::Request* request,
+ const GoogleServiceAuthError& error) override;
// net::URLFetcherDelegate implementation.
- virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
+ void OnURLFetchComplete(const net::URLFetcher* source) override;
private:
+ FRIEND_TEST_ALL_PREFIXES(AttachmentDownloaderImplTest, ExtractCrc32c_First);
+ FRIEND_TEST_ALL_PREFIXES(AttachmentDownloaderImplTest, ExtractCrc32c_None);
+ FRIEND_TEST_ALL_PREFIXES(AttachmentDownloaderImplTest, ExtractCrc32c_Empty);
+
struct DownloadState;
typedef std::string AttachmentUrl;
typedef base::ScopedPtrHashMap<AttachmentUrl, DownloadState> StateMap;
const DownloadResult& result,
const scoped_refptr<base::RefCountedString>& attachment_data);
+ // Verify the integrity of |data| using the hash received in |fetcher|.
+ //
+ // Assumes that the request in |fetcher| has completed.
+ //
+ // Returns true if the hash of |data| matches the hash contained in |fetcher|
+ // or if |fetcher| contains no hash (no hash, no problem).
+ static bool VerifyHashIfPresent(const net::URLFetcher& fetcher,
+ const std::string& data);
+
+ // Extract the crc32c from an X-Goog-Hash header in |headers|.
+ //
+ // Return true if a crc32c was found and set |crc32c|.
+ SYNC_EXPORT_PRIVATE static bool ExtractCrc32c(
+ const net::HttpResponseHeaders& headers,
+ std::string* crc32c);
+
GURL sync_service_url_;
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;