| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  * Copyright (C) 2010 Google Inc.  All rights reserved. |    2  * Copyright (C) 2010 Google Inc.  All rights reserved. | 
|    3  * |    3  * | 
|    4  * Redistribution and use in source and binary forms, with or without |    4  * Redistribution and use in source and binary forms, with or without | 
|    5  * modification, are permitted provided that the following conditions are |    5  * modification, are permitted provided that the following conditions are | 
|    6  * met: |    6  * met: | 
|    7  * |    7  * | 
|    8  *     * Redistributions of source code must retain the above copyright |    8  *     * Redistributions of source code must retain the above copyright | 
|    9  * notice, this list of conditions and the following disclaimer. |    9  * notice, this list of conditions and the following disclaimer. | 
|   10  *     * Redistributions in binary form must reproduce the above |   10  *     * Redistributions in binary form must reproduce the above | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
|   29  */ |   29  */ | 
|   30  |   30  | 
|   31 #include "core/fileapi/FileReaderSync.h" |   31 #include "core/fileapi/FileReaderSync.h" | 
|   32  |   32  | 
|   33 #include "bindings/core/v8/ExceptionState.h" |   33 #include "bindings/core/v8/ExceptionState.h" | 
|   34 #include "bindings/core/v8/ScriptState.h" |   34 #include "bindings/core/v8/ScriptState.h" | 
|   35 #include "core/dom/DOMArrayBuffer.h" |   35 #include "core/dom/DOMArrayBuffer.h" | 
|   36 #include "core/fileapi/Blob.h" |   36 #include "core/fileapi/Blob.h" | 
|   37 #include "core/fileapi/FileError.h" |   37 #include "core/fileapi/FileError.h" | 
|   38 #include "core/fileapi/FileReaderLoader.h" |   38 #include "core/fileapi/FileReaderLoader.h" | 
 |   39 #include "platform/Histogram.h" | 
|   39  |   40  | 
|   40 namespace blink { |   41 namespace blink { | 
|   41  |   42  | 
|   42 FileReaderSync::FileReaderSync() {} |   43 namespace { | 
 |   44 // These values are written to logs.  New enum values can be added, but existing | 
 |   45 // enums must never be renumbered or deleted and reused. | 
 |   46 enum class WorkerType { | 
 |   47   OTHER = 0, | 
 |   48   DEDICATED_WORKER = 1, | 
 |   49   SHARED_WORKER = 2, | 
 |   50   SERVICE_WORKER = 3, | 
 |   51   MAX | 
 |   52 }; | 
 |   53 }  // namespace | 
 |   54  | 
 |   55 FileReaderSync::FileReaderSync(ExecutionContext* context) { | 
 |   56   WorkerType type = WorkerType::OTHER; | 
 |   57   if (context->isDedicatedWorkerGlobalScope()) | 
 |   58     type = WorkerType::DEDICATED_WORKER; | 
 |   59   else if (context->isSharedWorkerGlobalScope()) | 
 |   60     type = WorkerType::SHARED_WORKER; | 
 |   61   else if (context->isServiceWorkerGlobalScope()) | 
 |   62     type = WorkerType::SERVICE_WORKER; | 
 |   63   DEFINE_THREAD_SAFE_STATIC_LOCAL( | 
 |   64       EnumerationHistogram, workerTypeHistogram, | 
 |   65       new EnumerationHistogram("FileReaderSync.WorkerType", | 
 |   66                                static_cast<int>(WorkerType::MAX))); | 
 |   67   workerTypeHistogram.count(static_cast<int>(type)); | 
 |   68 } | 
|   43  |   69  | 
|   44 DOMArrayBuffer* FileReaderSync::readAsArrayBuffer( |   70 DOMArrayBuffer* FileReaderSync::readAsArrayBuffer( | 
|   45     ScriptState* scriptState, |   71     ScriptState* scriptState, | 
|   46     Blob* blob, |   72     Blob* blob, | 
|   47     ExceptionState& exceptionState) { |   73     ExceptionState& exceptionState) { | 
|   48   ASSERT(blob); |   74   ASSERT(blob); | 
|   49  |   75  | 
|   50   std::unique_ptr<FileReaderLoader> loader = |   76   std::unique_ptr<FileReaderLoader> loader = | 
|   51       FileReaderLoader::create(FileReaderLoader::ReadAsArrayBuffer, nullptr); |   77       FileReaderLoader::create(FileReaderLoader::ReadAsArrayBuffer, nullptr); | 
|   52   startLoading(scriptState->getExecutionContext(), *loader, *blob, |   78   startLoading(scriptState->getExecutionContext(), *loader, *blob, | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   97 void FileReaderSync::startLoading(ExecutionContext* executionContext, |  123 void FileReaderSync::startLoading(ExecutionContext* executionContext, | 
|   98                                   FileReaderLoader& loader, |  124                                   FileReaderLoader& loader, | 
|   99                                   const Blob& blob, |  125                                   const Blob& blob, | 
|  100                                   ExceptionState& exceptionState) { |  126                                   ExceptionState& exceptionState) { | 
|  101   loader.start(executionContext, blob.blobDataHandle()); |  127   loader.start(executionContext, blob.blobDataHandle()); | 
|  102   if (loader.errorCode()) |  128   if (loader.errorCode()) | 
|  103     FileError::throwDOMException(exceptionState, loader.errorCode()); |  129     FileError::throwDOMException(exceptionState, loader.errorCode()); | 
|  104 } |  130 } | 
|  105  |  131  | 
|  106 }  // namespace blink |  132 }  // namespace blink | 
| OLD | NEW |